예제 #1
0
        public async System.Threading.Tasks.Task <ActionResult> Detail(int id)
        {
            var bienBanService = this.Service <IBienBanService>();
            var model          = new BienBanEditViewModel(await bienBanService.GetAsync(id));

            if (model == null || !model.Active)
            {
                return(HttpNotFound());
            }
            return(View(model));
        }
예제 #2
0
        public ActionResult Create()
        {
            var bienBanService        = this.Service <IBienBanService>();
            var thongTinCaNhanService = this.Service <IThongTinCaNhanService>();
            var model = new BienBanEditViewModel();

            model.AvailableThongTinCaNhan = thongTinCaNhanService.GetActive()
                                            .AsEnumerable()
                                            .Select(q => new SelectListItem()
            {
                Text     = q.HoTen + " - " + q.NgaySinh.ToShortDateString(),
                Value    = q.Id.ToString(),
                Selected = false,
            });
            return(View(model));
        }
예제 #3
0
        public async System.Threading.Tasks.Task <ActionResult> Edit(int id)
        {
            var bienBanService        = this.Service <IBienBanService>();
            var thongTinCaNhanService = this.Service <IThongTinCaNhanService>();
            var model = new BienBanEditViewModel(await bienBanService.GetAsync(id));

            model.AvailableThongTinCaNhan = thongTinCaNhanService.GetActive()
                                            .AsEnumerable()
                                            .Select(q => new SelectListItem()
            {
                Text     = q.HoTen + " - " + q.NgaySinh.ToShortDateString(),
                Value    = q.Id.ToString(),
                Selected = model.id == q.Id,
            });
            return(View(model));
        }
예제 #4
0
        public async System.Threading.Tasks.Task <JsonResult> Create(BienBanEditViewModel model)
        {
            var bienBanService = this.Service <IBienBanService>();

            try
            {
                #region Get Hinh Anh
                string        hinhAnhPath  = "";
                string        root         = Server.MapPath("~");
                string        parent       = Path.GetDirectoryName(root);
                string        grandParent  = Path.GetDirectoryName(parent);
                string        serverPath   = grandParent + "/BienBan/";
                List <string> imgExtension = new List <string>()
                {
                    ".jpg", ".jpeg", ".png"
                };
                if (model.SelectedHinhAnh != null)
                {
                    string brandLogoFileExtension = Path.GetExtension(model.SelectedHinhAnh.FileName);
                    if (!imgExtension.Contains(brandLogoFileExtension.ToLower()))
                    {
                        return(Json(new { success = false, message = Resource.InvalidImageFile }));
                    }
                    string hinhAnhFileName = "BienBan_" + Guid.NewGuid().ToString("N") + brandLogoFileExtension;
                    //model.HinhAnhLogo.SaveAs(serverPath + hinhAnhFileName);
                    //temp
                    model.SelectedHinhAnh.SaveAs(HttpContext.Server.MapPath("~/BienBan/") + hinhAnhFileName);
                    hinhAnhPath = "/BienBan/" + hinhAnhFileName;
                }
                #endregion
                model.HinhAnh = hinhAnhPath;
                model.Active  = true;
                var entity = model.ToEntity();
                await bienBanService.CreateAsync(entity);

                string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
                var    result         = await new SystemLogController().Create("Tạo", controllerName, entity.id);
                return(Json(new { success = true, message = "Tạo biên bản thành công!" }));
            }
            catch (Exception e)
            {
                return(Json(new { success = false, message = Resource.ErrorMessage }));
            }
        }
예제 #5
0
        public async System.Threading.Tasks.Task <JsonResult> Edit(BienBanEditViewModel model)
        {
            var bienBanService        = this.Service <IBienBanService>();
            var thongTinCaNhanService = this.Service <IThongTinCaNhanService>();
            var entity = await bienBanService.GetAsync(model.id);

            try
            {
                #region Get Hinh Anh
                string        hinhAnhPath  = "";
                string        root         = Server.MapPath("~");
                string        parent       = Path.GetDirectoryName(root);
                string        grandParent  = Path.GetDirectoryName(parent);
                string        serverPath   = grandParent + "/BienBan/";
                List <string> imgExtension = new List <string>()
                {
                    ".jpg", ".jpeg", ".png"
                };
                if (model.SelectedHinhAnh != null)
                {
                    string brandLogoFileExtension = Path.GetExtension(model.SelectedHinhAnh.FileName);
                    if (!imgExtension.Contains(brandLogoFileExtension.ToLower()))
                    {
                        return(Json(new { success = false, message = Resource.InvalidImageFile }));
                    }
                    string hinhAnhFileName = "BienBan_" + Guid.NewGuid().ToString("N") + brandLogoFileExtension;
                    //model.HinhAnhLogo.SaveAs(serverPath + hinhAnhFileName);
                    //temp
                    model.SelectedHinhAnh.SaveAs(HttpContext.Server.MapPath("~/BienBan/") + hinhAnhFileName);
                    hinhAnhPath = "/BienBan/" + hinhAnhFileName;
                    #region Delete old file
                    string strPhysicalFolder = Server.MapPath("~/");

                    string strFileFullPath = strPhysicalFolder + entity.HinhAnh;

                    if (System.IO.File.Exists(strFileFullPath))
                    {
                        System.IO.File.Delete(strFileFullPath);
                    }
                    #endregion
                }
                else
                {
                    hinhAnhPath = entity.HinhAnh;
                }
                model.HinhAnh = hinhAnhPath;
                #endregion
                model.CopyToEntity(entity);
                entity.Active         = true;
                entity.ThongTinCaNhan = await thongTinCaNhanService.GetAsync(entity.idThongTinCaNhan);

                await bienBanService.UpdateAsync(entity);

                string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
                var    result         = await new SystemLogController().Create("Sửa", controllerName, entity.id);
                return(Json(new { success = true, message = "Lưu biên bản thành công!" }));
            }
            catch (Exception e)
            {
                return(Json(new { success = false, message = Resource.ErrorMessage }));
            }
        }