Ejemplo n.º 1
0
        public ActionResult Create()
        {
            if (!_nguoiDungServices.isLoggedIn())
            {
                TempData["Message"]  = "Bạn chưa đăng nhập, vui lòng đăng nhập";
                TempData["NotiType"] = "danger";                 //success là class trong bootstrap
                return(RedirectToAction("Login", "NguoiDung"));
            }
            if (!_quyenServices.Authorize((int)EnumQuyen.LOAIPHONG_THEM))
            {
                return(RedirectToAction("ViewDenied", "QLKS"));
            }
            var loaiPhongModel = new LoaiPhongModel();
            var maxId          = db.LOAIPHONGs.Select(c => c.ID).DefaultIfEmpty(0).Max();
            var newId          = (maxId + 1).ToString().PadLeft(7, '0');

            loaiPhongModel.Ma = "LP" + "-" + newId;
            return(View(loaiPhongModel));
        }
Ejemplo n.º 2
0
        public ActionResult Create(LoaiPhongModel model, HttpPostedFileBase UploadImage)
        {
            if (!_quyenServices.Authorize((int)EnumQuyen.LOAIPHONG_THEM))
            {
                return(RedirectToAction("ViewDenied", "QLKS"));
            }
            if (!ModelState.IsValid)
            {
                TempData["Message"]  = "Có lỗi xảy ra! Vui lòng kiểm tra lại thông tin.";
                TempData["NotiType"] = "success";                 //success là class trong bootstrap
                return(View("Create", model));
            }
            if (UploadImage != null)
            {
                if (UploadImage.ContentType == "image/jpg" || UploadImage.ContentType == "image/png" || UploadImage.ContentType == "image/jpeg")
                {
                    string fileName = Path.GetFileName(DateTime.Now.ToString("ddMMyyyy_hhmmss_tt_") + "" + UploadImage.FileName);
                    string path     = Path.Combine(Server.MapPath("~/Content/imgLoaiPhong"), fileName);
                    UploadImage.SaveAs(path);
                    //UploadImage.SaveAs(Server.MapPath("/") + "/Content/imgLoaiPhong/" + DateTime.Now.ToString("ddMMyyyy_hhmmss_tt_") + UploadImage.FileName);
                    model.AnhDaiDien = fileName;
                }
                else
                {
                    ModelState.AddModelError("", "lỗi dữ liệu ảnh !");
                }
            }
            var item = AutoMapper.Mapper.Map <LOAIPHONG>(model);
            //db.LOAIPHONGs.Add(item);
            int a = 0;

            if (item.ThongTin == null)
            {
                item.ThongTin = "";
            }
            a = db.Database.ExecuteSqlCommand("exec SP_CreateOrUpdate_LOAIPHONG @Type, @ID, @Ten, @Ma, @AnhDaiDien, @ThongTin, @GiaThue, @SoNguoiLon, @SoTreEm, @SoGiuongDon, @SoGiuongDoi, @UpdateID", new SqlParameter("@Type", int.Parse("0")), new SqlParameter("@ID", a), new SqlParameter("@Ten", item.Ten), new SqlParameter("@Ma", item.Ma), new SqlParameter("@AnhDaiDien", model.AnhDaiDien), new SqlParameter("@ThongTin", item.ThongTin), new SqlParameter("@GiaThue", item.GiaThue), new SqlParameter("@SoNguoiLon", item.SoNguoiLon), new SqlParameter("@SoTreEm", item.SoTreEm), new SqlParameter("@SoGiuongDoi", item.SoGiuongDoi), new SqlParameter("@SoGiuongDon", item.SoGiuongDon), new SqlParameter("@UpdateID", int.Parse("0")));
            db.SaveChanges();
            _lichSuServices.LuuLichSu((int)Session["ID"], (int)EnumLoaiHanhDong.THEM, item.GetType().ToString());
            TempData["Message"]  = "Thêm mới thành công";
            TempData["NotiType"] = "success";
            return(RedirectToAction("List"));
        }