コード例 #1
0
        public ActionResult Create(Plan plan, List <int> Options, HttpPostedFileBase PlanImage)
        {
            if (plan.RentPrice == null)
            {
                plan.RentPrice = 0;
            }

            if (ModelState.IsValid)
            {
                #region Upload Files
                if (PlanImage != null)
                {
                    // Saving Temp Image
                    var newFileName = Guid.NewGuid() + Path.GetExtension(PlanImage.FileName);
                    PlanImage.SaveAs(Server.MapPath("/Files/PlanFiles/Temp/" + newFileName));
                    // Resize Image
                    ImageResizer image = new ImageResizer(370, 270, true);
                    image.Resize(Server.MapPath("/Files/PlanFiles/Temp/" + newFileName),
                                 Server.MapPath("/Files/PlanFiles/PlanImages/" + newFileName));
                    // Deleting Temp Image
                    System.IO.File.Delete(Server.MapPath("/Files/PlanFiles/Temp/" + newFileName));

                    plan.Image = newFileName;
                }
                #endregion
                _repo.Add(plan);
                foreach (var option in Options)
                {
                    _repo.AddOption(plan.Id, option);
                }
                return(RedirectToAction("Index", new { realStateId = plan.RealStateId }));
            }
            ViewBag.RealStateId = plan.RealStateId;
            return(View(plan));
        }
コード例 #2
0
        public void AddPlan(Plan plan)
        {
            if (plan.Created == null)
            {
                plan.Created = DateTime.UtcNow;
            }

            _plansRepository.Add(plan);
        }
コード例 #3
0
        public ActionResult Create([Bind("Name,Type,Users,Status,StartDate,EndDate,Description,Cost")] Plansend plans)
        {
            if (ModelState.IsValid)
            {
                plansRepository.Add(plans);
                return(RedirectToAction("Index"));
            }

            return(NoContent());
        }