Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Update multistep wizard data in not strongly typed view

$
0
0

hello all

in my mvc project, i have implemented a not strongly typed form with multi steps wizard view, for create and update object in database by entity framework.

for create an object , i have stored this new object in session variable like in this tutorial part2 and part 1   

and each post action i get this object from session and move the each step value in that object

but for update i have to get that object by its Id from database. and for this i have to keep the object Id throught all wizard step action methodes, butI unable to retrieve the id

in each step action methode. any idea?

there  is  my controller  code:

//model class
publiic class InvoiceDTO
{
   public Invoice Invoice{get; set;}
   public List<Expense> Expenses{get; set;}
}

//store object in session variable
private InvoiceDTO GetInvoice(int invoiceId)
        {
             //get invoice object from database
            Session["Invoice"] = GetSingleInvoiceDto(invoiceId);
            if (Session["Invoice"] == null)
            {
                Session["Invoice"] = new InvoiceDTO();
            }

            return (InvoiceDTO)Session["Invoice"];
        }

[HttpGet]
        public PartialViewResult CreateEditInvoice(int id)
        {
            InvoiceDTO invoiceDto=null;
            
            if (id <= 0)
            {

                ViewBag.StructureId = new SelectList(uniteOfWorkBll.StructureBLL.GetListStructures(), "StructureId", "Designation");
            }
            else
            {
                invoiceDto = GetInvoice(id);
                ViewBag.Id = invoiceDto.Invoice.Id;
                ViewBag.Number = invoiceDto.Invoice.Number ;
                ViewBag.Periode = invoiceDto.Invoice.Periode;
                ViewBag.StartDate = invoiceDto.Invoice.StartDate;
                ViewBag.EndDate = invoiceDto.Invoice.EndDate ;
                ViewBag.InitialBalance =invoiceDto.Invoice.InitialBalance ;
                ViewBag.StructureId = new SelectList(GetListStructures(), "StructureId", "Designation", draDto.DRA.StructureId);               
            }
            return PartialView(invoiceDto);
        }
//first step post
        [HttpPost]
        public ActionResult _FirstCreateStep(int Id, int? structureId, string number)
        {
            //the Id parameter from hidden feild in step form
                InvoiceDTO invoiceDto = GetInvoice(Id);
                if (invoiceDto.Invoice <= 0)
                {
                    invoiceDto.Invoice = new Invoice ();
                }

                
                invoiceDto.Invoice.StructureId = structureId;
                invoiceDto.Invoice.Number = number;
                context.SaveChanges();
                ViewBag.StructureId = new SelectList(GetListStructures(), "StructureId", "Designation", structureId);
                return PartialView("_SecondCreateStep");
            }
        }
//second step post 
        [HttpPost]
        public ActionResult _SecondCreateStep(DateTime? periode, DateTime? startDate, DateTime? endDate)
        {
            InvoiceDTO invoiceDto = GetInvoice(Id);//how i get the id
                invoiceDto.Invoice.Periode =periode;
                invoiceDto.Invoice.StartDate = startDate;
                invoiceDto.Invoice.EndDate = endDate;
                context.SaveChanges();
                return PartialView("_ThirdCreateStep");
            }
        }
        //third step post
        [HttpPost]
        public ActionResult _ThirdCreateStep(decimal initialBalance)
        {
            InvoiceDTO invoiceDto = GetInvoice(Id);//how to get id;
            if (ModelState.IsValid)
            {             
                invoiceDto.Invoice.InitialBalance= initialBalance;
                 context.SaveChanges();
                ///vue partiel pour la reutilisation
                return PartialView("Details", invoiceDto.Invoice);
            }
            else
            {
                ViewBag.StructureId = new SelectList(GetListStructures(), "Id", "Designation");

                return PartialView(invoiceDto);
            }
        }


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>