Пример #1
0
        public ActionResult Edit(int id)
        {
            try
            {
                // get sand info
                var editedSand = db.Sands.Where(s => s.SandId == id).FirstOrDefault();
                if (editedSand != null)
                {
                    // create view model
                    EditSandViewModel model = new EditSandViewModel();
                    model.SandId         = editedSand.SandId;
                    model.SandName       = editedSand.SandName;
                    model.ProviderPrice  = editedSand.ProviderPrice;
                    model.CustomerPrice  = editedSand.CustomerPrice;
                    model.TransportPrice = editedSand.TransportPrice;
                    model.Description    = editedSand.Description;

                    return(View(model));
                }

                // sand info not found
                return(RedirectToAction("Message", "Error",
                                        new RouteValueDictionary(
                                            new { message = "Sản phẩm cát #" + id + " không tồn tại trong hệ thống!!!" })));
            }
            catch (Exception ex)
            {
                // error
                return(RedirectToAction("Message", "Error",
                                        new RouteValueDictionary(
                                            new { message = ex.Message })));
            }
        }
Пример #2
0
        public ActionResult Edit(EditSandViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    // get sand info
                    var editedSand = db.Sands.Where(s => s.SandId == model.SandId).FirstOrDefault();

                    // update sand info
                    if (editedSand != null)
                    {
                        string actionLogData =
                            "  sandId=" + editedSand.SandId +
                            ", oldSandName=" + editedSand.SandName +
                            ", oldProviderPrice=" + editedSand.ProviderPrice +
                            ", oldCustomerPrice=" + editedSand.CustomerPrice +
                            ", oldTransportPrice=" + editedSand.TransportPrice;

                        editedSand.SandName       = model.SandName;
                        editedSand.ProviderPrice  = model.ProviderPrice;
                        editedSand.CustomerPrice  = model.CustomerPrice;
                        editedSand.TransportPrice = model.TransportPrice;
                        editedSand.Description    = model.Description;
                        db.SaveChanges();

                        // Write action log
                        actionLogData +=
                            ", new_SandName=" + editedSand.SandName +
                            ", new_ProviderPrice=" + editedSand.ProviderPrice +
                            ", new_CustomerPrice=" + editedSand.CustomerPrice +
                            ", new_TransportPrice=" + editedSand.TransportPrice;

                        ActionLog.WriteLog(ActionLog.EDIT_SAND_INFO, actionLogData, User.Identity.Name, Request.ServerVariables["REMOTE_ADDR"]);

                        return(RedirectToAction("Index"));
                    }

                    return(RedirectToAction("Message", "Error",
                                            new RouteValueDictionary(
                                                new { message = "Sản phẩm cát #" + model.SandId + " không tồn tại trong hệ thống!!!" })));
                }

                ModelState.AddModelError("", "Thông tin cập nhật không hợp lệ!!!");
            }
            catch (Exception ex)
            {
                // error
                ModelState.AddModelError("", ex.Message);
            }

            return(View(model));
        }