Esempio n. 1
0
        public async Task <ActionResult> _Edit(EditBranchModel model)
        {
            var nameResponse = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Get, $"Administration/Branch/IsNameExist?id={model.Id}&name={model.Name}");

            if (nameResponse.isSuccess)
            {
                TempData["ErrorMessage"] = Language.Branch.ValidExistName;
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                var response = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Put, $"Administration/Branch?id={model.Id}", model);

                if (response.isSuccess)
                {
                    TempData["SuccessMessage"] = Language.Branch.AlertSuccessUpdate;

                    await LogActivity(Modules.Setting, "Update Parameter Branch", model);

                    return(RedirectToAction("List"));
                }
            }

            TempData["ErrorMessage"] = Language.Branch.AlertFailUpdate;

            return(RedirectToAction("List"));
        }
Esempio n. 2
0
        public IHttpActionResult Update(EditBranchModel model)
        {
            IHttpActionResult httpActionResult;
            Branch            branch = db.Branches.FirstOrDefault(x => x.Id == model.id);

            if (branch == null)
            {
                error.Add("Not Found");
                httpActionResult = new ErrorActionResult(Request, HttpStatusCode.NotFound, error);
            }
            if (string.IsNullOrEmpty(model.Name) && CheckPhoneNumber.CheckCorrectPhoneNumber(model.PhoneNumber))
            {
                error.Add("Name is required");
                httpActionResult = new ErrorActionResult(Request, HttpStatusCode.BadRequest, error);
            }
            else
            {
                branch.BranchCode  = model.BranchCode ?? model.BranchCode;
                branch.Name        = model.Name ?? model.Name;
                branch.PhoneNumber = model.PhoneNumber ?? model.PhoneNumber;
                branch.Address     = model.Address ?? model.Address;
                branch.Status      = model.Status;
                branch.UpdatedDate = DateTime.Now;
                branch.UpdatedBy   = User.Identity.Name;

                db.Entry(branch).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                httpActionResult = Ok(new BranchModel(branch));
            }
            return(httpActionResult);
        }
Esempio n. 3
0
        public async Task <ActionResult> _Edit(int id, string No, int StateId, string Name)
        {
            var model = new EditBranchModel
            {
                Id      = id,
                No      = No,
                StateId = StateId,
                Name    = Name
            };

            model.States = new SelectList(await GetStates(), "Id", "Name", 0);

            return(View(model));
        }
Esempio n. 4
0
        public IHttpActionResult Put(int id, [FromBody] EditBranchModel model)
        {
            var branch = db.Branch.Where(s => s.Id == id).FirstOrDefault();

            if (branch != null)
            {
                branch.Name    = model.Name;
                branch.StateId = model.StateId;

                db.Entry(branch).State = EntityState.Modified;
                db.Entry(branch).Property(x => x.Display).IsModified = false;

                db.SaveChanges();

                return(Ok(true));
            }
            else
            {
                return(NotFound());
            }
        }