コード例 #1
0
 public ActionResult AddDispensaries(DispensariesViewModel disvm)
 {
     if (Session["UserId"] != null)
     {
         int userid = int.Parse(Session["UserId"].ToString());
         int dispensaryId = _dbds.insertDispensary(disMaps.DispensaryVMtoDispenary(disvm), userid);
         Session["dispensaryId"] = dispensaryId.ToString();
         return RedirectToAction("AddDispensariesDetail", "Properties");
     }
     else
     {
         return RedirectToAction("LogIn", "Home");
     }
 }
コード例 #2
0
        public ActionResult EditDispensary(DispensariesViewModel disvm, HttpPostedFileBase avtar)
        {
            if (Session["UserId"] != null)
            {
                if (Session["dispensaryId"] != null)
                {
                    int userid = int.Parse(Session["UserId"].ToString());
                    int dispensaryId = int.Parse(Session["dispensaryId"].ToString());
                    if (avtar != null && avtar.ContentLength > 0)
                    {
                        string ext = avtar.FileName;
                        ext = ext.Substring(ext.LastIndexOf("."));
                        if (ext == ".jpg" || ext == ".jpeg" || ext == ".png")
                        {
                            var fileName = Path.GetFileName(avtar.FileName);
                            string originalpath = avtar.FileName;
                            fileName = fileName.Substring(0, fileName.LastIndexOf(".") - 1);
                            fileName = fileName + DateTime.Now.Ticks.ToString() + ext;
                            var path = Path.Combine(Server.MapPath("~/DispensaryImages/"), fileName);
                            avtar.SaveAs(path);
                            string path1 = "~/DispensaryImages/" + fileName;
                            disvm.AvtarName = avtar.FileName;
                            disvm.AvtarPathName = path1;
                        }
                        else
                        {
                            ViewBag.Message = "Invalid Image.";
                            return View();
                        }
                    }

                    _dbds.UpadteDispensary(disMaps.DispensaryVMtoDispenary(disvm), dispensaryId);
                    ViewBag.success = "Dispensary Successfully Updated";
                    return View(disMaps.DispenaryToDispenaryVM(_dbds.GetDispensaryData(dispensaryId), _db.GetUserProfile(userid)));
                }
                else
                {
                    return RedirectToAction("AddDispensaries", "Properties");
                }
            }
            else
            {
                return RedirectToAction("LogIn", "Home");
            }
        }