Exemplo n.º 1
0
        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());
            }
        }
Exemplo n.º 2
0
 public int Insert(CMS_MapService entity)
 {
     try
     {
         MyContext.CMS_MapService.Add(entity);
         MyContext.SaveChanges();
         return(entity.ID);
     }
     catch (Exception ex)
     {
         Logs.WriteLog(ex);
         throw;
     }
 }
Exemplo n.º 3
0
        public bool Update(CMS_MapService entity)
        {
            try
            {
                //CMS_MapService obj = MyContext.CMS_MapService.Find(entity.ID);
                //obj.Name = entity.Name;
                //obj.Description = entity.Description;
                //obj.TypeOfMapID = entity.TypeOfMapID;
                //obj.UserCreate = entity.UserCreate;
                //entity.CreateDate = System.DateTime.Now;

                //MyContext.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                Logs.WriteLog(ex);
                return(false);
            }
        }
Exemplo n.º 4
0
        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());
            }
        }