예제 #1
0
        public ActionResult Update(int?Id)
        {
            IndentViewModel model = new IndentViewModel();

            model.Id            = 0;
            model.ItemViewModel = new ItemViewModel {
                Id = Id ?? 0
            };
            return(View(model));
        }
예제 #2
0
        public ActionResult Add()
        {
            IndentViewModel model = new IndentViewModel();

            model.Id            = 0;
            model.ItemViewModel = new ItemViewModel {
                Id = 0
            };
            return(View(model));
        }
예제 #3
0
        public ActionResult CreateIndent()
        {
            if (TempData["ErrorMessage"] != null)
            {
                ViewBag.ErrorMessage = TempData["ErrorMessage"];
            }

            var clientId = Session["Id"];

            if (clientId == null)
            {
                return(RedirectToAction("Registration", "Customer"));
            }

            IndentViewModel indentViewModel = new IndentViewModel();

            return(View(indentViewModel));
        }
        public async Task <ActionResult> SaveIndent(IndentViewModel indentViewModel, string indentCategory, string indentPrice)
        {
            var clientId = Session["Id"];

            if (clientId == null)
            {
                return(RedirectToAction("Registration", "Customer"));
            }

            int customerId = Convert.ToInt32(clientId);

            string imgSrc = null;
            string fileMimeType;

            if (indentViewModel.IndentDate.Year < DateTime.Now.Year ||
                (indentViewModel.IndentDate.Year == DateTime.Now.Year && indentViewModel.IndentDate.Month < DateTime.Now.Month) ||
                (indentViewModel.IndentDate.Year == DateTime.Now.Year && indentViewModel.IndentDate.Month == DateTime.Now.Month &&
                 indentViewModel.IndentDate.Day < DateTime.Now.Day))
            {
                TempData["ErrorMessage"] = "Были введены некорректные данные, попробуйте снова!";

                return(RedirectToAction("CreateIndent", "Customer"));
            }

            if (Request.Files.Count > 0)
            {
                HttpPostedFileBase file = Request.Files[0];

                fileMimeType = file.ContentType;

                if (!fileMimeType.Equals("application/octet-stream"))
                {
                    if (fileMimeType.Equals("image/jpeg"))
                    {
                        imgSrc = Path.Combine(Server.MapPath("~/Content/Indent"), "indentId.jpeg");
                        if (System.IO.File.Exists(imgSrc))
                        {
                            System.IO.File.Delete(imgSrc);
                        }
                    }
                    else
                    {
                        TempData["ErrorMessage"] = "Загружать фотографии разрешается только в jpeg формате!";

                        return(RedirectToAction("CreateIndent", "Customer"));
                    }
                }
            }

            double?priceOfIndent;

            Regex patternForPrice = new Regex(@"^[0-9]*\,?[0-9]+\s?$", RegexOptions.IgnoreCase);

            if (indentPrice == null)
            {
                priceOfIndent = null;
            }
            else if (patternForPrice.IsMatch(indentPrice.Trim()))
            {
                try
                {
                    priceOfIndent = Convert.ToDouble(indentPrice.Trim());
                }
                catch (Exception e)
                {
                    TempData["ErrorMessage"] = "Были введены некорректные данные, попробуйте снова!";

                    return(RedirectToAction("CreateIndent", "Customer"));
                }
            }
            else
            {
                TempData["ErrorMessage"] = "Были введены некорректные данные, попробуйте снова!";

                return(RedirectToAction("CreateIndent", "Customer"));
            }

            if (indentViewModel.Title == null || indentViewModel.City == null || indentViewModel.IndentDescription == null)
            {
                TempData["ErrorMessage"] = "Были введены некорректные данные, попробуйте снова!";

                return(RedirectToAction("CreateIndent", "Customer"));
            }

            if (Session["Language"] != null)
            {
                string lan = Session["Language"].ToString();

                if (lan == "en")
                {
                    indentViewModel.Category = CategoryExtension.
                                               TranslateFromEnglishToEnumEquivalents(new string[] { indentCategory }).FirstOrDefault();
                }
                else
                {
                    indentViewModel.Category = CategoryExtension.
                                               TranslateFromRussianToEnumEquivalents(new string[] { indentCategory }).FirstOrDefault();
                }
            }

            indentViewModel.Price    = priceOfIndent;
            indentViewModel.ImgSrc   = imgSrc;
            indentViewModel.Customer = new CustomerDTO()
            {
                CustomerId = customerId
            };

            IndentDTO indentDTO = _mapper.Map <IndentDTO>(indentViewModel);
            int?      indentId;

            try
            {
                indentId = await _indentService.Create(indentDTO);
            }
            catch (ValidationException e)
            {
                TempData["ErrorMessage"] = e.Message;

                return(RedirectToAction("CreateIndent", "Customer"));
            }

            if (imgSrc != null)
            {
                imgSrc = imgSrc.Replace("indentId", indentId.ToString());
                Request.Files[0].SaveAs(imgSrc);
            }

            return(RedirectToAction("GetCustomerIndents", "Customer"));
        }
        ///<summary>
        ///Returns view which contains indent model with: indent data, recalls, responces.
        ///Defines client opportunities to: write recall/responce, choose executor for indent.
        ///</summary>
        public ActionResult ShowIndent(int?id)
        {
            if (TempData["ErrorMessage"] != null)
            {
                ViewBag.ErrorMessage = TempData["ErrorMessage"];
            }

            IndentDTO indentDTO = null;
            int       indentId  = id ?? default(int);

            string cacheKey = "show-indent-" + indentId.ToString();

            indentDTO = HttpContext.Cache[cacheKey] as IndentDTO;

            if (indentDTO == null)
            {
                try
                {
                    indentDTO = _indentService.Get(indentId);
                }
                catch (ValidationException e)
                {
                    return(new HttpStatusCodeResult(404));
                }

                HttpContext.Cache.Insert(cacheKey, indentDTO, null, DateTime.Now.AddSeconds(120), TimeSpan.Zero);
            }

            var    claimIdentity = HttpContext.User.Identity as ClaimsIdentity;
            string role          = "";
            Role?  clientRole    = null;
            int?   clientId      = null;

            if (claimIdentity != null)
            {
                var roleClaim = claimIdentity.FindFirst(ClaimsIdentity.DefaultRoleClaimType);
                if (roleClaim != null)
                {
                    role       = roleClaim.Value.Trim();
                    clientRole = (Role)Enum.Parse(typeof(Role), role);
                }
            }

            var varClientId = Session["Id"];

            if (varClientId != null)
            {
                clientId = Convert.ToInt32(varClientId);
            }

            HelpModelForClientOpportunities clientOpportunities = new HelpModelForClientOpportunities();

            if (clientId != null && clientRole != null)
            {
                clientOpportunities = SetClientOpportunities(indentDTO, clientRole, clientId);
            }

            IndentViewModel indentViewModel = _mapper.Map <IndentViewModel>(indentDTO);

            IndentFullViewModel indentFullViewModel = new IndentFullViewModel()
            {
                indentViewModel     = indentViewModel,
                clientOpportunities = clientOpportunities
            };

            return(View(indentFullViewModel));
        }
예제 #6
0
 public IndentFullViewModel()
 {
     indentViewModel     = new IndentViewModel();
     clientOpportunities = new HelpModelForClientOpportunities();
 }