コード例 #1
0
        public static CommandResult ChangePassword(string userName, string oldPassword, string newPassword)
        {
            using (var context = new GST_MockProjectEntities())
            {
                using (System.Data.Entity.DbContextTransaction dbTran = context.Database.BeginTransaction())
                {
                    var user = context.USERs.FirstOrDefault(x => x.UserName == userName);
                    if (user == null)
                    {
                        return(new CommandResult(ResultCode.Fail, "User không tồn tại"));
                    }
                    else
                    {
                        var passMD5 = Encryptor.MD5Hash(oldPassword);
                        if (user.Password != passMD5)
                        {
                            return(new CommandResult(ResultCode.Fail, "Mật khẩu cũ không đúng"));
                        }
                        user.Password = Encryptor.MD5Hash(newPassword);
                        context.SaveChanges();
                    }



                    dbTran.Commit();

                    return(new CommandResult(ResultCode.Success, "Đổi mật khẩu thành công."));
                }
            }
        }
コード例 #2
0
        //hàm tạo mới 1 hóa đơn sẽ tự tạo các chi tiết hóa đơn
        public static CommandResult Create1(BILL c, int userId, string[] listSanphamID, string[] listSoluong, string[] listGia)

        {
            using (var context = new GST_MockProjectEntities())
            {
                using (System.Data.Entity.DbContextTransaction dbTran = context.Database.BeginTransaction())
                {
                    decimal?Tongtien = 0;

                    c.CreateBy   = userId;
                    c.Amount     = 0;
                    c.CreateDate = DateTime.Now;

                    context.BILLs.Add(c);
                    context.SaveChanges();



                    //luu chi tiet san pham
                    var listwtd = new List <BILL_DETAIL>();
                    for (var i = 0; i < listSanphamID.Length; i++)
                    {
                        decimal?price = null;
                        if (listGia[i] != "")
                        {
                            price    = decimal.Parse(listGia[i]);
                            Tongtien = Tongtien + price;
                        }

                        var wtd = new BILL_DETAIL()
                        {
                            Bill_ID    = c.ID,
                            Product_ID = int.Parse(listSanphamID[i]),
                            Quantity   = int.Parse(listSoluong[i]),
                            Amount     = price
                        };
                        listwtd.Add(wtd);
                    }

                    context.BILL_DETAIL.AddRange(listwtd);
                    c.Amount = Tongtien;
                    context.SaveChanges();
                    dbTran.Commit();
                    return(new CommandResult());
                }
            }
        }
コード例 #3
0
 public static CommandResult Delete(PRODUCT c)
 {
     using (var context = new GST_MockProjectEntities())
     {
         var Sanpham = context.PRODUCTs.First(x => x.ID == c.ID);
         Sanpham.Status = false;
         context.SaveChanges();
         return(new CommandResult());
     }
 }
コード例 #4
0
 public static CommandResult Create(PRODUCT_TYPE c)
 {
     using (var context = new GST_MockProjectEntities())
     {
         context.PRODUCT_TYPE.Add(c);
         context.SaveChanges();
         //TODO
         //context.Log(c, LogType.BankBranch_Create, userId, "", HttpContext.Current.Request.Form);
         return(new CommandResult());
     }
 }
コード例 #5
0
        public static CommandResult Create(USER c)
        {
            //Tạo 1 nhân viên mới
            using (var context = new GST_MockProjectEntities())
            {
                c.Password = Encryptor.MD5Hash(c.Password);
                context.USERs.Add(c);
                context.SaveChanges();

                return(new CommandResult());
            }
        }
コード例 #6
0
 public static void ChangeStatusNotifyId(long?id)
 {
     using (var context = new GST_MockProjectEntities())
     {
         var model = context.NOTIFies.Where(x => x.ID == id).FirstOrDefault();
         if (model != null)
         {
             model.Status = Notifi_Status.AnXem;
             context.SaveChanges();
         }
     }
 }
コード例 #7
0
        //chỉnh sửa hóa đơn + ch tiết hóa đơn
        //public static CommandResult Edit1(HOADON c, int userId, int flag, long? warehousePlace, List<string> fileList, string[] listProductId, string[] listQuantity, string[] listQuantityApprove, string[] listPrice)
        public static CommandResult Edit1(BILL c, int userId, string[] listSanphamID, string[] listSoluong, string[] listGia)
        {
            using (var context = new GST_MockProjectEntities())
            {
                using (System.Data.Entity.DbContextTransaction dbTran = context.Database.BeginTransaction())
                {
                    decimal?Tongtien = 0;

                    var HoaDon =
                        context.BILLs.Include(x => x.BILL_DETAIL).First(x => x.ID == c.ID);



                    //xóa danh sách sản phẩm cũ
                    var listwtdOld = HoaDon.BILL_DETAIL;
                    context.BILL_DETAIL.RemoveRange(listwtdOld);

                    //thêm danh sách sản phẩm mới
                    var listwtd = new List <BILL_DETAIL>();
                    for (int i = 0; i < listSanphamID.Length; i++)
                    {
                        var     SanphamID = int.Parse(listSanphamID[i]);
                        var     Soluong   = int.Parse(listSoluong[i]);
                        decimal?Giaban    = null;
                        if (listGia[i] != "")
                        {
                            Giaban   = decimal.Parse(listGia[i]);
                            Tongtien = Tongtien + Giaban;
                        }
                        var cthd = new BILL_DETAIL()
                        {
                            Product_ID = SanphamID,
                            Quantity   = Soluong,
                            Bill_ID    = c.ID,
                            Amount     = Giaban
                        };
                        listwtd.Add(cthd);
                    }
                    context.BILL_DETAIL.AddRange(listwtd);
                    //Chỉnh sửa lại thông tin hóa đơn khi sửa
                    HoaDon.UpdateBy   = userId;
                    HoaDon.UpdateDate = DateTime.Now;
                    HoaDon.Amount     = Tongtien;

                    context.SaveChanges();
                    dbTran.Commit();

                    return(new CommandResult(ResultCode.Success, "Sửa thành công"));
                }
            }
        }
コード例 #8
0
 public static CommandResult Create(NOTIFY c)
 {
     using (var context = new GST_MockProjectEntities())
     {
         c.UserCreate = UserService.GetUserInfo().ID;
         c.TimeCreate = DateTime.Now;
         c.Status     = Notifi_Status.ChuaXem;
         context.NOTIFies.Add(c);
         context.SaveChanges();
         //TODO
         //context.Log(c, LogType.BankBranch_Create, userId, "", HttpContext.Current.Request.Form);
         return(new CommandResult());
     }
 }
コード例 #9
0
 public static void ChangeStatus()
 {
     using (var context = new GST_MockProjectEntities())
     {
         var model = context.NOTIFies.Where(x => x.Status == Notifi_Status.ChuaXem);
         if (model != null)
         {
             foreach (var item in model)
             {
                 item.Status = Notifi_Status.DaxXem;
             }
             context.SaveChanges();
         }
     }
 }
コード例 #10
0
        public static CommandResult Edit(PRODUCT_TYPE c)
        {
            using (var context = new GST_MockProjectEntities())
            {
                var Loaisanpham = context.PRODUCT_TYPE.First(x => x.ID == c.ID);

                Loaisanpham.ProductTypeName = c.ProductTypeName;
                Loaisanpham.Status          = c.Status;

                context.SaveChanges();
                //TODO
                // context.Log(c, LogType.Customer_Edit, userId, "", HttpContext.Current.Request.Form);
                return(new CommandResult());
            }
        }
コード例 #11
0
        public static CommandResult Edit(WAREHOUSE c)
        {
            using (var context = new GST_MockProjectEntities())
            {
                var Kho = context.WAREHOUSEs.First(x => x.ID == c.ID);

                Kho.WarehouseName = c.WarehouseName;
                Kho.Address       = c.Address;
                Kho.Status        = c.Status;
                context.SaveChanges();
                //TODO
                // context.Log(c, LogType.Customer_Edit, userId, "", HttpContext.Current.Request.Form);
                return(new CommandResult());
            }
        }
コード例 #12
0
        public static CommandResult Edit(WAREHOUSE_TRANSACTION c)
        {
            using (var context = new GST_MockProjectEntities())
            {
                var NhapXuatKho = context.WAREHOUSE_TRANSACTION.First(x => x.ID == c.ID);

                NhapXuatKho.CreateDate   = DateTime.Now;
                NhapXuatKho.Warehouse_ID = c.Warehouse_ID;
                NhapXuatKho.Type         = c.Type.Value;
                context.SaveChanges();
                //TODO
                // context.Log(c, LogType.Customer_Edit, userId, "", HttpContext.Current.Request.Form);
                return(new CommandResult());
            }
        }
コード例 #13
0
        public static CommandResult Edit(PRODUCT c)
        {
            using (var context = new GST_MockProjectEntities())
            {
                var Sanpham = context.PRODUCTs.First(x => x.ID == c.ID);
                Sanpham.ProductName = c.ProductName;
                Sanpham.Amount      = c.Amount;

                Sanpham.Unit = c.Unit;

                Sanpham.ProductType_ID = c.ProductType_ID;

                context.SaveChanges();
                //TODO
                // context.Log(c, LogType.Customer_Edit, userId, "", HttpContext.Current.Request.Form);
                return(new CommandResult());
            }
        }
コード例 #14
0
        // [ValidateAntiForgeryToken]
        public ActionResult ListPermission2(USER user, AddUserPermission model, string selectedPermissions)
        {
            //lấy ra các quyền nhân viên
            int[] SelectedGroupPermission = string.IsNullOrWhiteSpace(selectedPermissions) ? new int[0]
                    : selectedPermissions.Split(',').Select(x => int.Parse(x)).ToArray();

            user = db.USERs.Include(x => x.USER_PERMISSION).FirstOrDefault(x => x.ID == model.UserId);
            if (user == null)
            {
                return(HttpNotFound());
            }
            if (SelectedGroupPermission == null)
            {
                SelectedGroupPermission = new int[0];
            }
            //ktra selectedpermiss có quyền hay chưa
            var deleted = user.USER_PERMISSION.Where(x => SelectedGroupPermission.Contains(x.Permisstion_ID) == false);

            foreach (var userPermission in deleted.ToList())
            {
                db.USER_PERMISSION.Remove(userPermission);
            }
            var addNew = SelectedGroupPermission.Where(x => user.USER_PERMISSION.All(y => y.Permisstion_ID != x));

            foreach (var permissionId in addNew)
            {
                var permission = new USER_PERMISSION();
                permission.User_ID        = model.UserId;
                permission.Permisstion_ID = permissionId;
                db.USER_PERMISSION.Add(permission);
            }
            var log = new StringBuilder();

            log.Append(db.GetAddDeleteLog((USER_PERMISSION permission) => permission.Permisstion_ID));
            db.SaveChanges();
            return(Json(new RedirectCommand()
            {
                Code = ResultCode.Success, Message = "Cập nhật thành công", Url = Url.Action("ListPermission", new { id = user.ID })
            },
                        JsonRequestBehavior.AllowGet));
        }
コード例 #15
0
        public static CommandResult Edit(USER c)
        {
            //chỉnh sửa 1 nhân viên (không cho chỉnh sửa mật khẩu)
            using (var context = new GST_MockProjectEntities())
            {
                var NhanVien = context.USERs.First(x => x.ID == c.ID);

                NhanVien.FullName    = c.FullName;
                NhanVien.DateOfBirth = c.DateOfBirth;
                NhanVien.Sex         = c.Sex;
                NhanVien.Address     = c.Address;
                NhanVien.PhoneNumber = c.PhoneNumber;
                NhanVien.UserName    = c.UserName;
                NhanVien.Email       = c.Email;
                NhanVien.Office      = c.Office;
                NhanVien.Status      = c.Status;
                context.SaveChanges();

                return(new CommandResult());
            }
        }
コード例 #16
0
        public ActionResult SaveChangeImage(int id, HttpPostedFileBase ImageUser) //hàm lưu lại hình ảnh đã đổi
        {
            GST_MockProjectEntities db = new GST_MockProjectEntities();
            var imageUpdate            = db.USERs.Find(id);

            try
            {
                if (ImageUser != null)
                {
                    if (ImageUser.ContentLength > 0)
                    {
                        var pathFile      = "~/Content/UserImage/";
                        var fileNameinput = id.ToString() + Path.GetFileName(ImageUser.FileName);

                        var ext = Path.GetExtension(fileNameinput);
                        if (ext != ".jpg" && ext != ".png" && ext != ".gif")
                        {
                            return(RedirectToAction("ShowUpdateImage", "Account", new { id = id }));
                        }
                        var  fileName = id.ToString() + ".jpg";
                        bool exists   = System.IO.Directory.Exists(Server.MapPath(pathFile));
                        if (!exists)
                        {
                            System.IO.Directory.CreateDirectory(Server.MapPath(pathFile));
                        }
                        var path = Path.Combine(Server.MapPath(pathFile), fileName);
                        ImageUser.SaveAs(path);
                        imageUpdate.Image = fileName;
                    }
                    db.Entry(imageUpdate).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            catch (RetryLimitExceededException)
            {
                ModelState.AddModelError("", "Error Save Data");
            }

            return(RedirectToAction("Profile", "Account", new { id = id }));
        }
コード例 #17
0
        public static CommandResult Create(BILL c)
        {
            using (var context = new GST_MockProjectEntities())
            {
                c.CreateBy   = UserService.GetUserInfo().ID;;
                c.CreateDate = DateTime.Now;
                context.BILLs.Add(c);
                context.SaveChanges();
                //TODO
                //context.Log(c, LogType.BankBranch_Create, userId, "", HttpContext.Current.Request.Form);
                return(new CommandResult());
            }
            //using (var context = new GST_MockProjectEntities())
            //{
            //    c.NhanVienID = 1;
            //    c.NgayLap = DateTime.Now;
            //    context.HOADONs.Add(c);
            //    context.SaveChanges();

            //    return new CommandResult();
            //}
        }