Exemplo n.º 1
0
        public ActionResult DeleteConfirmed([Bind(Include = "Id")] DossiersSitesFromViewModel cpt_calsses)
        {
            DossiersSitesPivot cods  = Mapper.Map <DossiersSitesFromViewModel, DossiersSitesPivot>(cpt_calsses);
            DossiersSitesPivot codes = dossiersSiteServise.GetDossiersSitePivot(cods.Id);


            dossiersSiteServise.DeleteDossiersSitePivot(codes);
            // db.SaveChanges();
            dossiersSiteServise.SaveDossiersSite();
            return(RedirectToAction("Index"));
        }
        public ActionResult SaveDataSites()
        {
            GridModel gridModel = new GridModel();
            List <Transaction <DossiersSitesPivot> > transactions = gridModel.LoadTransactions <DossiersSitesPivot>(HttpContext.Request.Form["ig_transactions"]);
            //var orders = RepositoryFactory.GetOrderRepository();
            long idDossier = 0;

            foreach (Transaction <DossiersSitesPivot> t in transactions)
            {
                int id = 0;
                Int32.TryParse(t.rowId, out id);

                if (idDossier == 0)
                {
                    if (t.row != null)
                    {
                        long.TryParse(t.row.IdDossier.Value.ToString(), out idDossier);
                        if (idDossier == 0)
                        {
                            //  var gEN_Dossiers = db.GEN_Dossiers.Where(x => x.Actif == false && x.CodeDossier == "").FirstOrDefault();
                            var gEN_Dossiers = dossiersServise.getingDossierActif();
                            if (gEN_Dossiers == null)
                            {
                                gEN_Dossiers = new DossiersPivot();
                                gEN_Dossiers.DossierActif         = false;
                                gEN_Dossiers.CodeDossier          = "";
                                gEN_Dossiers.DossierRaisonSociale = "";
                                //using (var dbIgnoreValidation = new StoreEntities())
                                //{
                                //    dbIgnoreValidation.Configuration.ValidateOnSaveEnabled = false;
                                //    dbIgnoreValidation.Dossiers.Add();
                                //    //Add(gEN_Dossiers);
                                //    dbIgnoreValidation.SaveChanges();
                                //}
                                dossiersServise.Validation_Db(gEN_Dossiers);

                                //db.GEN_Dossiers.Add(gEN_Dossiers);
                                //db.SaveChanges();
                            }
                            idDossier = gEN_Dossiers.DossierId;
                        }
                    }
                }


                //var row = db.GEN_DossiersSites.Find(id);
                var row = dossiersSitesService.GetDossiersSitePivot(id);
                if ((t.type == "newrow") || (row == null && (t.type == "row")))
                {
                    t.row.IdDossier        = idDossier;
                    t.row.sys_dateCreation = DateTime.Now;
                    t.row.sys_dateUpdate   = DateTime.Now;
                    t.row.sys_user         = Constantes.IdentifiantUser;
                    //t.row.Actif = true;
                    //db.GEN_DossiersSites.Add(t.row);
                    dossiersSitesService.CreateDossiersSitePivot(t.row);
                    /***/ dossiersSitesService.SaveDossiersSite();
                }
                else if (t.type == "deleterow")
                {
                    //var row = db.GEN_DossiersSites.Find(id);
                    if (row != null)
                    {
                        // db.GEN_DossiersSites.Remove(row);
                        dossiersSitesService.DeleteDossiersSitePivot(row);
                        /***/ dossiersSitesService.SaveDossiersSite();
                    }
                }
                else if (t.type == "row")
                {
                    row.Nom        = t.row.Nom;
                    row.Adresse    = t.row.Adresse;
                    row.ParDefault = t.row.ParDefault;
                    row.Actif      = t.row.Actif;
                    row.Adresse    = t.row.Adresse;
                    row.Email      = t.row.Email;
                    row.Tel        = t.row.Tel;
                    row.Fax        = t.row.Fax;
                    //row.IdDossier = t.row.IdDossier;
                    row.Pays             = t.row.Pays;
                    row.Ville            = t.row.Ville;
                    t.row.sys_dateUpdate = DateTime.Now;
                    //row.Civilite = t.row.Civilite;
                    //row.Nom = t.row.Nom;
                    //row.Prenom = t.row.Prenom;
                    //row.Tel = t.row.Tel;
                    //row.Email = t.row.Email;

                    // db.Entry(row).State = EntityState.Modified;
                    dossiersSitesService.UpdateDossierSitePivot(row);
                    /****/
                    dossiersSitesService.SaveDossiersSite();
                }
            }

            // db.SaveChanges();
            dossiersSitesService.SaveDossiersSite();
            JsonResult result = new JsonResult();
            Dictionary <string, bool> response = new Dictionary <string, bool>();

            response.Add("Success", true);
            result.Data = response;
            return(result);
        }