Esempio n. 1
0
        public ActionResult Create([Bind] RepairViewModel repair, string returnUrl)
        {
            ActionResult action;

            try
            {
                if (!ModelState.IsValid)
                {
                    ModelState.AddModelError("", MessageUI.ErrorMessage);
                    return(View(repair));
                }

                var files           = Request.Files;
                var repairGalleries = new List <RepairGallery>();
                if (files.Count > 0)
                {
                    var count   = files.Count - 1;
                    var num     = 0;
                    var allKeys = files.AllKeys;
                    for (var i = 0; i < allKeys.Length; i++)
                    {
                        var str = allKeys[i];
                        if (num <= count)
                        {
                            if (!str.Equals("ImageBigSize"))
                            {
                                var httpPostedFileBase = files[num];
                                if (httpPostedFileBase.ContentLength > 0)
                                {
                                    var repairGalleryViewModel = new RepairGalleryViewModel
                                    {
                                        RepairId = repair.Id
                                    };
                                    var str1 = $"{repair.RepairCode}-{Guid.NewGuid()}.jpg";
                                    _imagePlugin.CropAndResizeImage(httpPostedFileBase,
                                                                    $"{Contains.MenuFolder}{repair.RepairCode}/", str1, ImageSize.WithBigSize, ImageSize.WithBigSize);
                                    repairGalleryViewModel.ImagePath =
                                        $"{Contains.MenuFolder}{repair.RepairCode}/{str1}";
                                    repairGalleries.Add(Mapper.Map <RepairGallery>(repairGalleryViewModel));
                                }
                                num++;
                            }
                            else
                            {
                                num++;
                            }
                        }
                    }
                }
                var repair1 = Mapper.Map <RepairViewModel, Repair>(repair);
                if (repairGalleries.IsAny())
                {
                    repair1.RepairGalleries = repairGalleries;
                }
                var repairItems = new List <RepairItem>();
                if (repair.RepairItems.IsAny())
                {
                    repairItems.AddRange(
                        from item in repair.RepairItems
                        select Mapper.Map <RepairItem>(item));
                }
                if (repairItems.IsAny())
                {
                    repair1.RepairItems = repairItems;
                }
                _repairService.Create(repair1);
                Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.Repair)));
                if (!Url.IsLocalUrl(returnUrl) || returnUrl.Length <= 1 || !returnUrl.StartsWith("/") || returnUrl.StartsWith("//") || returnUrl.StartsWith("/\\"))
                {
                    action = RedirectToAction("Index");
                }
                else
                {
                    action = Redirect(returnUrl);
                }
            }
            catch (Exception exception1)
            {
                var exception = exception1;
                ExtentionUtils.Log(string.Concat("Repair.Create: ", exception.Message));
                ModelState.AddModelError("", exception.Message);
                return(View(repair));
            }
            return(action);
        }
Esempio n. 2
0
        public ActionResult Create([Bind] RepairViewModel repair, string ReturnUrl)
        {
            ActionResult action;

            try
            {
                if (!base.ModelState.IsValid)
                {
                    base.ModelState.AddModelError("", MessageUI.ErrorMessage);
                    return(base.View(repair));
                }
                else
                {
                    HttpFileCollectionBase files           = base.Request.Files;
                    List <RepairGallery>   repairGalleries = new List <RepairGallery>();
                    if (files.Count > 0)
                    {
                        int      count   = files.Count - 1;
                        int      num     = 0;
                        string[] allKeys = files.AllKeys;
                        for (int i = 0; i < (int)allKeys.Length; i++)
                        {
                            string str = allKeys[i];
                            if (num <= count)
                            {
                                if (!str.Equals("Image"))
                                {
                                    HttpPostedFileBase httpPostedFileBase = files[num];
                                    if (httpPostedFileBase.ContentLength > 0)
                                    {
                                        RepairGalleryViewModel repairGalleryViewModel = new RepairGalleryViewModel()
                                        {
                                            RepairId = repair.Id
                                        };
                                        string str1 = string.Format("{0}-{1}.jpg", repair.RepairCode, Guid.NewGuid());
                                        this._imagePlugin.CropAndResizeImage(httpPostedFileBase, string.Format("{0}{1}/", Contains.ImageFolder, repair.RepairCode), str1, ImageSize.WithBigSize, ImageSize.WithBigSize, false);
                                        repairGalleryViewModel.ImagePath = string.Format("{0}{1}/{2}", Contains.ImageFolder, repair.RepairCode, str1);
                                        repairGalleries.Add(Mapper.Map <RepairGallery>(repairGalleryViewModel));
                                    }
                                    num++;
                                }
                                else
                                {
                                    num++;
                                }
                            }
                        }
                    }
                    Repair repair1 = Mapper.Map <RepairViewModel, Repair>(repair);
                    if (repairGalleries.IsAny <RepairGallery>())
                    {
                        repair1.RepairGalleries = repairGalleries;
                    }
                    List <RepairItem> repairItems = new List <RepairItem>();
                    if (repair.RepairItems.IsAny <RepairItemViewModel>())
                    {
                        repairItems.AddRange(
                            from item in repair.RepairItems
                            select Mapper.Map <RepairItem>(item));
                    }
                    if (repairItems.IsAny <RepairItem>())
                    {
                        repair1.RepairItems = repairItems;
                    }
                    this._repairService.Create(repair1);
                    base.Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.Repair)));
                    if (!base.Url.IsLocalUrl(ReturnUrl) || ReturnUrl.Length <= 1 || !ReturnUrl.StartsWith("/") || ReturnUrl.StartsWith("//") || ReturnUrl.StartsWith("/\\"))
                    {
                        action = base.RedirectToAction("Index");
                    }
                    else
                    {
                        action = this.Redirect(ReturnUrl);
                    }
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                ExtentionUtils.Log(string.Concat("Repair.Create: ", exception.Message));
                base.ModelState.AddModelError("", exception.Message);
                return(base.View(repair));
            }
            return(action);
        }
Esempio n. 3
0
        public ActionResult Edit([Bind] RepairViewModel repairView, string returnUrl)
        {
            ActionResult action;

            try
            {
                if (!ModelState.IsValid)
                {
                    ModelState.AddModelError("", MessageUI.ErrorMessage);
                    return(View(repairView));
                }

                var repair             = _repairService.Get(x => x.Id == repairView.Id);
                var files              = Request.Files;
                var lstRepairGalleries = new List <RepairGallery>();
                if (files.Count > 0)
                {
                    var count   = files.Count - 1;
                    var num     = 0;
                    var allKeys = files.AllKeys;
                    for (var i = 0; i < allKeys.Length; i++)
                    {
                        var str = allKeys[i];
                        if (num <= count)
                        {
                            if (!str.Equals("ImageBigSize"))
                            {
                                var item = files[num];
                                if (item.ContentLength > 0)
                                {
                                    var repairGalleryViewModel = new RepairGalleryViewModel
                                    {
                                        RepairId = repairView.Id
                                    };
                                    var str1 = $"{repairView.RepairCode}-{Guid.NewGuid()}.jpg";
                                    _imagePlugin.CropAndResizeImage(item,
                                                                    $"{Contains.MenuFolder}{repairView.RepairCode}/", str1, ImageSize.WithBigSize, ImageSize.WithBigSize);
                                    repairGalleryViewModel.ImagePath =
                                        $"{Contains.MenuFolder}{repairView.RepairCode}/{str1}";
                                    lstRepairGalleries.Add(Mapper.Map <RepairGallery>(repairGalleryViewModel));
                                }
                                num++;
                            }
                            else
                            {
                                num++;
                            }
                        }
                    }
                }
                if (lstRepairGalleries.IsAny())
                {
                    repair.RepairGalleries = lstRepairGalleries;
                }
                var repairItems = new List <RepairItem>();
                if (repairView.RepairItems.IsAny())
                {
                    foreach (var repairItem in repairView.RepairItems)
                    {
                        var repairItemViewModel = new RepairItemViewModel();
                        if (repairItem.Id > 0)
                        {
                            repairItemViewModel.Id = repairItem.Id;
                        }
                        repairItemViewModel.RepairId     = repairView.Id;
                        repairItemViewModel.FixedFee     = repairItem.FixedFee;
                        repairItemViewModel.Category     = repairItem.Category;
                        repairItemViewModel.WarrantyFrom = repairItem.WarrantyFrom;
                        repairItemViewModel.WarrantyTo   = repairItem.WarrantyTo;
                        repairItems.Add(Mapper.Map <RepairItem>(repairItemViewModel));
                    }
                }
                if (repairItems.IsAny())
                {
                    repair.RepairItems = repairItems;
                }
                var repairItems1 = _repairItemService.FindBy(x => x.RepairId == repairView.Id);
                _repairItemService.BatchDelete(repairItems1);
                repair = Mapper.Map(repairView, repair);
                _repairService.Update(repair);
                Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.UpdateSuccess, FormUI.Repair)));
                if (!Url.IsLocalUrl(returnUrl) || returnUrl.Length <= 1 || !returnUrl.StartsWith("/") || returnUrl.StartsWith("//") || returnUrl.StartsWith("/\\"))
                {
                    action = RedirectToAction("Index");
                }
                else
                {
                    action = Redirect(returnUrl);
                }
            }
            catch (Exception exception1)
            {
                var exception = exception1;
                ModelState.AddModelError("", exception.Message);
                ExtentionUtils.Log(string.Concat("Repair.Edit: ", exception.Message));
                return(View(repairView));
            }
            return(action);
        }
Esempio n. 4
0
        public ActionResult Edit([Bind] RepairViewModel repairView, string ReturnUrl)
        {
            ActionResult action;

            try
            {
                if (!base.ModelState.IsValid)
                {
                    base.ModelState.AddModelError("", MessageUI.ErrorMessage);
                    return(base.View(repairView));
                }
                else
                {
                    Repair repair = this._repairService.Get((Repair x) => x.Id == repairView.Id, false);
                    HttpFileCollectionBase files = base.Request.Files;
                    List <RepairGallery>   lstRepairGalleries = new List <RepairGallery>();
                    if (files.Count > 0)
                    {
                        int      count   = files.Count - 1;
                        int      num     = 0;
                        string[] allKeys = files.AllKeys;
                        for (int i = 0; i < (int)allKeys.Length; i++)
                        {
                            string str = allKeys[i];
                            if (num <= count)
                            {
                                if (!str.Equals("Image"))
                                {
                                    HttpPostedFileBase item = files[num];
                                    if (item.ContentLength > 0)
                                    {
                                        RepairGalleryViewModel repairGalleryViewModel = new RepairGalleryViewModel()
                                        {
                                            RepairId = repairView.Id
                                        };
                                        string str1 = string.Format("{0}-{1}.jpg", repairView.RepairCode, Guid.NewGuid());
                                        this._imagePlugin.CropAndResizeImage(item, string.Format("{0}{1}/", Contains.ImageFolder, repairView.RepairCode), str1, ImageSize.WithBigSize, ImageSize.WithBigSize, false);
                                        repairGalleryViewModel.ImagePath = string.Format("{0}{1}/{2}", Contains.ImageFolder, repairView.RepairCode, str1);
                                        lstRepairGalleries.Add(Mapper.Map <RepairGallery>(repairGalleryViewModel));
                                    }
                                    num++;
                                }
                                else
                                {
                                    num++;
                                }
                            }
                        }
                    }
                    if (lstRepairGalleries.IsAny <RepairGallery>())
                    {
                        repair.RepairGalleries = lstRepairGalleries;
                    }
                    List <RepairItem> repairItems = new List <RepairItem>();
                    if (repairView.RepairItems.IsAny <RepairItemViewModel>())
                    {
                        foreach (RepairItemViewModel repairItem in repairView.RepairItems)
                        {
                            RepairItemViewModel repairItemViewModel = new RepairItemViewModel();
                            if (repairItem.Id > 0)
                            {
                                repairItemViewModel.Id = repairItem.Id;
                            }
                            repairItemViewModel.RepairId     = repairView.Id;
                            repairItemViewModel.FixedFee     = repairItem.FixedFee;
                            repairItemViewModel.Category     = repairItem.Category;
                            repairItemViewModel.WarrantyFrom = repairItem.WarrantyFrom;
                            repairItemViewModel.WarrantyTo   = repairItem.WarrantyTo;
                            repairItems.Add(Mapper.Map <RepairItem>(repairItemViewModel));
                        }
                    }
                    if (repairItems.IsAny <RepairItem>())
                    {
                        repair.RepairItems = repairItems;
                    }
                    IEnumerable <RepairItem> repairItems1 = this._repairItemService.FindBy((RepairItem x) => x.RepairId == repairView.Id, false);
                    this._repairItemService.BatchDelete(repairItems1);
                    repair = Mapper.Map <RepairViewModel, Repair>(repairView, repair);
                    this._repairService.Update(repair);
                    base.Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.UpdateSuccess, FormUI.Repair)));
                    if (!base.Url.IsLocalUrl(ReturnUrl) || ReturnUrl.Length <= 1 || !ReturnUrl.StartsWith("/") || ReturnUrl.StartsWith("//") || ReturnUrl.StartsWith("/\\"))
                    {
                        action = base.RedirectToAction("Index");
                    }
                    else
                    {
                        action = this.Redirect(ReturnUrl);
                    }
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                base.ModelState.AddModelError("", exception.Message);
                ExtentionUtils.Log(string.Concat("Repair.Edit: ", exception.Message));
                return(base.View(repairView));
            }
            return(action);
        }