public int SaveDataStaff(StaffModel data) { try { if (data.StaffID == 0) { var staffcheck = _context.STAFFs.Where(x => x.UserName == data.UserName).ToList(); if (staffcheck.Count > 0) { return(-1); } var staff = new STAFF(); staff.Status = 1; staff.Fname = data.Fname; staff.Lname = data.Lname; staff.UserName = data.UserName; staff.Password = StaffModel.Encrypt(data.Password); staff.CreateBy = data.UpdateBy; staff.CreateDate = DateTime.Now; staff.UpdateBy = data.UpdateBy; staff.UpdateDate = DateTime.Now; staff.DepartmentID = data.DepartmentID; _context.Entry(staff).State = EntityState.Added; _context.SaveChanges(); return(1); } else { var staffcheck = _context.STAFFs.Where(x => x.UserName == data.UserName && x.StaffID != data.StaffID).ToList(); if (staffcheck.Count > 0) { return(-1); } var staff = _context.STAFFs.Find(data.StaffID); if (staff != null) { staff.Fname = data.Fname; staff.Lname = data.Lname; staff.UserName = data.UserName; staff.Password = StaffModel.Encrypt(data.Password); staff.UpdateBy = data.UpdateBy; staff.UpdateDate = DateTime.Now; staff.DepartmentID = data.DepartmentID; _context.Entry(staff).State = EntityState.Modified; _context.SaveChanges(); return(1); } return(0); } } catch (Exception ex) { LogPOS.WriteLog("SaveDataStaff :::::::::::::::::::::::::" + ex.Message); return(0); } }