예제 #1
0
        public JsonResult EditMerchant(AddMerchantViewModel model)
        {
            try
            {
                using (var db = new TourEntities())
                {
                    var formsAuthentication = HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName] != null
                  ? FormsAuthentication.Decrypt(
                        HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName].Value)
                  : null;

                    if (ModelState.IsValid)
                    {
                        var merchant = db.Merchant.Find(model.MerchantId);

                        if (model.MerchantLogoPath != null)
                        {
                            FileInfo path = new FileInfo(Server.MapPath("~/Image/Merchant/" + merchant.MerchantLogoPath));
                            path.Delete();

                            string imageName = System.IO.Path.GetFileName(model.MerchantLogoPath.FileName);
                            imageName = MetadataServices.GetDateTimeWithoutSlash() + "-" + imageName;
                            string physicalPath = Server.MapPath("~/Image/Merchant/" + imageName);
                            model.MerchantLogoPath.SaveAs(physicalPath);

                            merchant.MerchantLogoPath = imageName;
                        }

                        merchant.MerchantId           = model.MerchantId;
                        merchant.MerchantName         = model.MerchantName;
                        merchant.MerchantRegisterCode = model.MerchantRegisterCode;
                        merchant.MerchantPhoneNumber  = model.MerchantPhoneNumber;
                        merchant.MerchantAddress      = model.MerchantAddress;
                        merchant.MerchantCategoryId   = model.GetMerchantCategoryId;
                        merchant.MerchantJoinDate     = model.MerchantJoinDate;
                        merchant.UpdatedBy            = MetadataServices.GetCurrentUser().Username;
                        merchant.UpdatedAt            = MetadataServices.GetCurrentDate();

                        db.SaveChanges();
                    }
                    return(Json(new { }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #2
0
        public ActionResult AddMerchant()
        {
            AddMerchantViewModel addMerchantVideModel = new AddMerchantViewModel();

            List <int> merchantCategory = new List <int>();

            using (var db = new TourEntities())
            {
                addMerchantVideModel.MerchantCategoryId = db.MerchantCategory.Select(e => new SelectListItem()
                {
                    Text  = e.CategoryName.ToString(),
                    Value = e.MerchantCategoryId.ToString(),
                }).ToList();
            }

            return(View(addMerchantVideModel));
        }
예제 #3
0
        public JsonResult AddMerchant(AddMerchantViewModel model)
        {
            using (var db = new TourEntities())
            {
                if (ModelState.IsValid)
                {
                    var formsAuthentication = HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName] != null
                    ? FormsAuthentication.Decrypt(
                        HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName].Value)
                    : null;

                    string imageName = System.IO.Path.GetFileName(model.MerchantLogoPath.FileName);
                    imageName = MetadataServices.GetDateTimeWithoutSlash() + "-" + imageName;
                    string physicalPath = Server.MapPath("~/Image/Merchant/" + imageName);
                    model.MerchantLogoPath.SaveAs(physicalPath);

                    var newMerchant = new Merchant()
                    {
                        MerchantId           = model.MerchantId,
                        MerchantName         = model.MerchantName,
                        MerchantRegisterCode = model.MerchantRegisterCode,
                        MerchantPhoneNumber  = model.MerchantPhoneNumber,
                        MerchantAddress      = model.MerchantAddress,
                        MerchantCategoryId   = model.GetMerchantCategoryId,
                        MerchantJoinDate     = model.MerchantJoinDate,
                        MerchantLogoPath     = imageName,
                        CreatedBy            = MetadataServices.GetCurrentUser().Username,
                        CreatedAt            = MetadataServices.GetCurrentDate(),
                        UpdatedBy            = MetadataServices.GetCurrentUser().Username,
                        UpdatedAt            = MetadataServices.GetCurrentDate()
                    };
                    db.Merchant.Add(newMerchant);
                    db.SaveChanges();
                }
                return(Json(new { }, JsonRequestBehavior.AllowGet));
            }
        }
예제 #4
0
 public AddMerchantPage(Action <Models.Merchant> onAdded = null)
 {
     InitializeComponent();
     BindingContext = new AddMerchantViewModel(onAdded);
 }