コード例 #1
0
        public ActionResult Create(Business model, IEnumerable<HttpPostedFileBase> attachments)
        {
            var cusr = Session["_CUSR"] as SessionUser;
            if (cusr == null) throw new ArgumentException("SessionUser");

            model.added_by = (byte)cusr.ID;
            model.added_on = DateTime.Now;

            try
            {
                if (attachments != null)
                {
                    foreach (var item in attachments)
                    {
                        if (item != null && item.ContentLength > 0)
                        {
                            var filename = Path.GetFileName(item.FileName).ToLower();
                            var dirpath = "~/Uploads/Business/" + GetFolderName(model);
                            var directory = Server.MapPath(dirpath);

                            if (!Directory.Exists(directory))
                                Directory.CreateDirectory(directory);

                            string path = Path.Combine(directory, filename);
                            string relPath = Path.Combine(dirpath, filename);
                            item.SaveAs(path);

                            model.Attachments.Add(new ProspectRealEstate.Web.Models.Attachment()
                            {
                                added_by = (byte)cusr.ID,
                                added_on = DateTime.Now,
                                Business = model,
                                file_location = relPath,
                                type = "image"
                            });
                        }
                    }
                }

                ModelState.Remove("Attachments");

                if (ModelState.IsValid)
                {
                    repository.InsertOrUpdate(model);
                    repository.SubmitChanges();
                    return RedirectToAction("Edit", new { id = model.ID });
                }
                else
                {
                    return View();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #2
0
 private void SetViewBag(Business model = null)
 {
     if (model == null)
     {
         this.SetLocationsViewBag(null, null, null);
         this.SetCategoriesViewBag(null);
         this.SetAgentsViewBag(null);
     }
     else
     {
         this.SetLocationsViewBag(model.suburb_id, model.state_id, model.country_id);
         this.SetCategoriesViewBag(model.category_id);
         this.SetAgentsViewBag(model.agent_id);
     }
 }
コード例 #3
0
 public ActionResult Create()
 {
     var model = new Business();
     SetViewBag(model);
     return View(model);
 }
コード例 #4
0
 private string GetFolderName(Business model)
 {
     return model.business_code;
 }