Exemplo n.º 1
0
        public ActionResult Edit(int id, EEdit model)
        {
            var svc = CreateEthicalService();

            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                else if (svc.UpdateEthicalOrganization(model, id))
                {
                    TempData["SaveResult"] = " Your organization was updated.";
                    return(RedirectToAction("Index"));
                }
            }
            catch
            {
                if (model.EthicalOrganizationId != id)
                {
                    ModelState.AddModelError("", "Ethical Organization ID Missmatch");
                    return(View(model));
                }
            }
            return(View(model));
        }
Exemplo n.º 2
0
        // Update
        // GET: Edit (Update)
        // Ethical/Edit/{id}
        public ActionResult Edit(int id)
        {
            var service = CreateEthicalService();
            var detail  = service.GetEthicalOrganizationById(id);
            var model   =
                new EEdit
            {
                EthicalOrganizationName = detail.EthicalOrganizationName,
                Sustainable             = detail.Sustainable,
                Diverse  = detail.Diverse,
                ECountry = detail.ECountry,
                EImprove = detail.EImprove
            };

            return(View(model));
        }
Exemplo n.º 3
0
        // Update
        public bool UpdateEthicalOrganization(EEdit model, int id)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .EthicalOrganizations
                    .Single(e => e.EthicalOrganizationId == id && e.Id == _userId);

                entity.EthicalOrganizationName = model.EthicalOrganizationName;
                entity.CrueltyFree             = model.CrueltyFree;
                entity.Sustainable             = model.Sustainable;
                entity.Diverse  = model.Diverse;
                entity.ECountry = model.ECountry;
                entity.EImprove = model.EImprove;

                return(ctx.SaveChanges() == 1);
            }
        }