public ActionResult EditBanDo(FormCollection fc, CMS_Maps obj) { try { if (ModelState.IsValid) { string strThumbnailDir = System.Configuration.ConfigurationManager.AppSettings["ThumbnailFileUrl"].ToString(); var item = Request.Files.AllKeys.Where(m => m.StartsWith("Thumbnail")).FirstOrDefault(); var imgThumbnail = Request.Files[item]; var fileName = "thumbnail_" + DateTime.Now.ToString("yyyyMMddhhmmsstt") + Guid.NewGuid().ToString() + Path.GetExtension(imgThumbnail.FileName); //if (imgThumbnail != null && imgThumbnail.ContentLength > 0) //{ // obj.Thumbnail = fileName; //} CMS_MapService objMapService = new CMS_MapService(); CMS_Maps_DAO objDAO = new CMS_Maps_DAO(); CMS_MapService_DAO objDAOMapService = new CMS_MapService_DAO(); string strIDService = "0"; if (fc["ddlServices"] != null) { strIDService = fc["ddlServices"].ToString(); } if (strIDService == "0") { SetAlert("Chọn Services", AlertType.Error); return(View()); } if (objDAO.Update(obj)) { // Save file var path = Path.Combine(Server.MapPath(strThumbnailDir), fileName); imgThumbnail.SaveAs(path); objDAOMapService.DeleteByIDMap(obj.ID); objMapService.MapID = obj.ID; objMapService.Orders = 0; objMapService.ServiceID = Convert.ToInt32(strIDService); objDAOMapService.Insert(objMapService); SetAlert("Cập nhật bản đồ thành công", AlertType.Success); return(RedirectToAction("Index", "CMS_Maps")); } else { SetAlert("Cập nhật bản đồ không thành công", AlertType.Error); } } return(View(obj)); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }
public int Insert(CMS_Maps entity) { try { entity.CreateDate = System.DateTime.Now; MyContext.CMS_Maps.Add(entity); MyContext.SaveChanges(); return(entity.ID); } catch (Exception ex) { Logs.WriteLog(ex); throw; } }
public bool Update(CMS_Maps entity) { try { CMS_Maps obj = MyContext.CMS_Maps.Find(entity.ID); obj.Name = entity.Name; obj.Description = entity.Description; obj.TypeOfMapID = entity.TypeOfMapID; obj.UserCreate = entity.UserCreate; //obj.Thumbnail = string.IsNullOrEmpty(obj.Thumbnail) ? "thumbnail_DEFAULT.jpg" : entity.Thumbnail; MyContext.SaveChanges(); return(true); } catch (Exception ex) { Logs.WriteLog(ex); return(false); } }
public ActionResult CreateBanDo(FormCollection fc, CMS_Maps obj) { try { if (ModelState.IsValid) { string strThumbnailDir = System.Configuration.ConfigurationManager.AppSettings["ThumbnailFileUrl"].ToString(); var item = Request.Files.AllKeys.Where(m => m.StartsWith("Thumbnail")).FirstOrDefault(); var imgThumbnail = Request.Files[item]; if (imgThumbnail != null && imgThumbnail.ContentLength > 0) { //var fileName = "thumbnail_" + DateTime.Now.ToString("yyyyMMddhhmmsstt") + Guid.NewGuid().ToString() + Path.GetExtension(imgThumbnail.FileName); //obj.Thumbnail = fileName; // Save file //var path = Path.Combine(Server.MapPath(strThumbnailDir), fileName); //imgThumbnail.SaveAs(path); } else { //obj.Thumbnail = "thumbnail_DEFAULT.jpg"; } CMS_MapService objMapService = new CMS_MapService(); CMS_Maps_DAO objDAO = new CMS_Maps_DAO(); CMS_MapService_DAO objDAOMapService = new CMS_MapService_DAO(); string strIDService = "0"; if (fc["ddlServices"] != null) { strIDService = fc["ddlServices"].ToString(); } if (strIDService == "0") { SetAlert("Chọn Services", AlertType.Error); return(View()); } CSF_Users_DAO objUserDao = new CSF_Users_DAO(); int intUserID = objUserDao.GetUserIDByUserName(HttpContext.User.Identity.Name); obj.UserCreate = intUserID; int ReturnID = objDAO.Insert(obj); if (ReturnID > 0) { objMapService.MapID = ReturnID; objMapService.Orders = 0; objMapService.ServiceID = Convert.ToInt32(strIDService); objDAOMapService.Insert(objMapService); SetAlert("Thêm bản đồ thành công", AlertType.Success); return(RedirectToAction("Index", "CMS_Maps")); } else { ModelState.AddModelError("", "Thêm bản đồ không thành công"); } return(View("Index")); } return(View()); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }