/// <summary> /// Validate the user against company /// </summary> /// <param name="userId"></param> /// <param name="companyId"></param> public bool ValidateUser(int userId, int companyId, string appType = "", string studentDetails = "") { try { using (DBEntity context = new DBEntity()) { //check whether the user has access to the company UserCompany userCompany = (from uc in context.UserCompany where uc.CompanyId == companyId && uc.IsEnabled && uc.Status == 1 && uc.UserId == userId select uc).FirstOrDefault(); if (userCompany != null) { //Validate the user report permissions PermissionManager permissionManager = new PermissionManager(Convert.ToInt64(userCompany.ReportsPerms)); if (CheckReportPermissions(permissionManager, appType)) { if (appType == Constants.QUERY_BUILDER && !string.IsNullOrEmpty(studentDetails)) { if (IsMyStudent(studentDetails, userCompany, userId, companyId)) { return(true); } else { return(false); } } return(true); } else { return(false); } } else { if (appType == Constants.TRAINING_DASHBOARD || appType == Constants.OQ_DASHBOARD) { bool clientCompany = (from uc in context.UserCompany join cc in context.CompanyClient on uc.CompanyId equals cc.OwnerCompany where uc.IsDefault && uc.IsEnabled && uc.Status == 1 && cc.IsEnabled && uc.UserId == userId && cc.ClientCompany == companyId select uc.UserId).ToList().Count > 0; if (clientCompany) { return(true); } else { return(false); } } else { return(false); } } } } catch (Exception validateUserException) { LambdaLogger.Log(validateUserException.ToString()); return(false); } }
public UserRegisterDTO InsertNewUser(User user, List <int> companiesId) { UserUtil Util = new UserService(); if (companiesId.Count() < 1) { throw new NotFoundException("Preencha o campo EMPRESA"); } if (Util.ObjectIsNull(user)) { throw new NotFoundException("Usuário não está preenchido!"); } if (!Util.ObjectIsNull(_repository.GetUserByCPF(user.CPF))) { throw new BadRequestException($"Já existe um usuário cadastrado com este cpf: {user.CPF}, faça login :)"); } if (Util.NameIsEmty(user)) { throw new BadRequestException($"Nome deve ser preenchido {user.Name}"); } if (Util.EmailIsEmpty(user)) { throw new BadRequestException($"Email deve ser preenchido {user.Email}"); } if (Util.StringIsNull(user.Password)) { throw new BadRequestException("SENHA deve ser preenchida"); } if (Util.CPFIsEmpty(user)) { throw new BadRequestException("CPF deve ser preenchido"); } try { List <UserCompany> usersCompany = new List <UserCompany>(); UserRegisterDTO userDTO = new UserRegisterDTO(); foreach (int id in companiesId) { UserCompany userCompany = new UserCompany(); userCompany.CompanyId = id; usersCompany.Add(userCompany); } user.UserCompanies = usersCompany; _repository.Create(user); userDTO.UserCompanies = usersCompany; userDTO.CPF = user.CPF; userDTO.Email = user.Email; userDTO.Name = user.Name; userDTO.UserEnum = user.UserEnum; userDTO.UserRole = user.UserRole; return(userDTO); } catch (Exception e) { throw new Exception($"Tipo da excessão: {e.GetType()}"); } }
public HttpResponseMessage Post([FromBody] UserCompany data) { return(requestHandler.CreateGbObject(Request, data)); }
public async Task <ActionResult <UserCompany> > RemoveUserFromCompanyAsync(UserCompany userCompany) { await _companyService.RemoveUserFromCompanyAsync(userCompany); return(Ok(userCompany)); }
public override object Save <T>(T entity) { BO.CompanyCaseConsentApproval companyCaseConsentApprovalBO = (BO.CompanyCaseConsentApproval)(object) entity; CompanyCaseConsentApproval companyCaseConsentApprovalDB = new CompanyCaseConsentApproval(); //using (var dbContextTransaction = _context.Database.BeginTransaction()) //{ if (companyCaseConsentApprovalBO != null) { int patient = _context.Cases.Where(p => p.Id == companyCaseConsentApprovalBO.CaseId && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).Select(p => p.PatientId).FirstOrDefault(); UserCompany userCompany = _context.UserCompanies.Where(p => p.UserID == patient && p.CompanyID == companyCaseConsentApprovalBO.CompanyId && p.IsAccepted == true && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).FirstOrDefault(); if (userCompany == null) { userCompany = new UserCompany(); userCompany.CompanyID = companyCaseConsentApprovalBO.CompanyId; userCompany.UserID = patient; userCompany.IsAccepted = true; userCompany = _context.UserCompanies.Add(userCompany); _context.SaveChanges(); } CaseCompanyMapping caseCompanyMapping = _context.CaseCompanyMappings.Where(p => p.CaseId == companyCaseConsentApprovalBO.CaseId && p.CompanyId == companyCaseConsentApprovalBO.CompanyId && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).FirstOrDefault(); if (caseCompanyMapping == null) { caseCompanyMapping = new CaseCompanyMapping(); var referredBy = _context.Referrals.Where(p => p.CaseId == companyCaseConsentApprovalBO.CaseId.Value && p.ToCompanyId == companyCaseConsentApprovalBO.CompanyId && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))) .Select(p2 => p2.FromCompanyId).FirstOrDefault(); caseCompanyMapping.CaseId = companyCaseConsentApprovalBO.CaseId.Value; caseCompanyMapping.CompanyId = companyCaseConsentApprovalBO.CompanyId; caseCompanyMapping.IsOriginator = false; // companyCaseConsentApprovalBO.IsOriginator; caseCompanyMapping.AddedByCompanyId = referredBy != 0 ? referredBy : companyCaseConsentApprovalBO.CompanyId; caseCompanyMapping = _context.CaseCompanyMappings.Add(caseCompanyMapping); _context.SaveChanges(); } companyCaseConsentApprovalDB = _context.CompanyCaseConsentApprovals.Where(p => p.CaseId == companyCaseConsentApprovalBO.CaseId && p.CompanyId == companyCaseConsentApprovalBO.CompanyId && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))) .FirstOrDefault(); bool Add_companyCaseConsentApproval = false; if (companyCaseConsentApprovalDB == null) { Add_companyCaseConsentApproval = true; companyCaseConsentApprovalDB = new CompanyCaseConsentApproval(); } else { return(new BO.ErrorObject { errorObject = "", ErrorMessage = "Company, Case and Consent data already exists.", ErrorLevel = ErrorLevel.Error }); } companyCaseConsentApprovalDB.CompanyId = companyCaseConsentApprovalBO.CompanyId; companyCaseConsentApprovalDB.CaseId = (int)companyCaseConsentApprovalBO.CaseId; if (companyCaseConsentApprovalDB.ConsentGivenTypeId <= 0) { companyCaseConsentApprovalDB.ConsentGivenTypeId = 1; } if (Add_companyCaseConsentApproval == true) { companyCaseConsentApprovalDB.CreateByUserID = 0; companyCaseConsentApprovalDB.CreateDate = DateTime.UtcNow; companyCaseConsentApprovalDB = _context.CompanyCaseConsentApprovals.Add(companyCaseConsentApprovalDB); } else { companyCaseConsentApprovalDB.UpdateByUserID = 0; companyCaseConsentApprovalDB.UpdateDate = DateTime.UtcNow; } _context.SaveChanges(); } else { return(new BO.ErrorObject { errorObject = "", ErrorMessage = "Please pass valid details.", ErrorLevel = ErrorLevel.Error }); } //dbContextTransaction.Commit(); companyCaseConsentApprovalDB = _context.CompanyCaseConsentApprovals.Include("Case") .Include("Company") .Include("ConsentGivenType") .Where(p => p.Id == companyCaseConsentApprovalDB.Id && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))) .FirstOrDefault <CompanyCaseConsentApproval>(); //} var res = Convert <BO.CompanyCaseConsentApproval, CompanyCaseConsentApproval>(companyCaseConsentApprovalDB); return((object)res); }
/// <summary> /// This method Saves Record into Database. /// </summary> /// <param name="objRetDC">Object containing Data values to be saved.</param> /// <returns>Boolean value True if Record is saved successfully /// otherwise returns False indicating Record is not saved.</returns> public static bool Save(ReturnableDC objRetDC, User currentUser) { int result = 0; UserCompany CurrentCompany = new UserCompany(); using (SqlConnection Conn = new SqlConnection(General.GetSQLConnectionString())) { string strSaveQry; if (objRetDC.IsNew) { strSaveQry = "INSERT INTO RETURNABLEDC(DBID, ENTRYNO, ENTRYDATE, ENTRYTYPE, " + " PARTYNAME, VEHICLENO, DCNO, DCDATE, PLANT, VINDATE, VINTIME, VOUTDATE, " + " VOUTTIME, ST_DATE, MODIFY_DATE, CRBY, MODBY, MACHINENAME) " + " VALUES (@dbId, @EntryNo, @EntryDate, @EntryType, @PartyName, @VehicleNo, " + " @DCNo, @DCDate, @Plant, @VinDate, @VinTime, @VOutDate, @VoutTime, " + " @STDate, @ModifyDate, @CrBy, @ModBy, @MachineName)"; } else { strSaveQry = "UPDATE RETURNABLEDC " + " SET ENTRYNO = @EntryNo, ENTRYDATE = @EntryDate, ENTRYTYPE = @EntryType, " + " PARTYNAME = @PartyName, VEHICLENO = @VehicleNo, DCNO = @DCNo, " + " DCDATE = @DCDate, PLANT = @Plant, VINDATE = @VInDate, VINTIME = @VInTime, " + " VOUTDATE = @VOutDate, VOUTTIME = @VOutTime, MODIFY_DATE = @ModifyDate, " + " MODBY = @ModBy, MACHINENAME = @MachineName " + " WHERE DBID = @dbId"; } try { SqlCommand objCmd = Conn.CreateCommand(); objCmd.CommandType = CommandType.Text; objCmd.CommandText = strSaveQry; objCmd.Parameters.AddWithValue("@EntryDate", objRetDC.EntryDate); objCmd.Parameters.AddWithValue("@EntryType", objRetDC.EntryType); objCmd.Parameters.AddWithValue("@PartyName", objRetDC.PartyName); if (objRetDC.VehicleNo == string.Empty) { objCmd.Parameters.AddWithValue("@VehicleNo", DBNull.Value); } else { objCmd.Parameters.AddWithValue("@VehicleNo", objRetDC.VehicleNo); } objCmd.Parameters.AddWithValue("@DCNo", objRetDC.DCNo); objCmd.Parameters.AddWithValue("@DCDate", objRetDC.DCDate); objCmd.Parameters.AddWithValue("@Plant", objRetDC.PlantName); if (objRetDC.VInDate == DateTime.MinValue) { objCmd.Parameters.AddWithValue("@VInDate", DBNull.Value); } else { objCmd.Parameters.AddWithValue("@VInDate", objRetDC.VInDate); } if (objRetDC.VInTime == DateTime.MinValue) { objCmd.Parameters.AddWithValue("@VInTime", DBNull.Value); } else { objCmd.Parameters.AddWithValue("@VInTime", objRetDC.VInTime); } if (objRetDC.VOutDate == DateTime.MinValue) { objCmd.Parameters.AddWithValue("@VOutDate", DBNull.Value); } else { objCmd.Parameters.AddWithValue("@VOutDate", objRetDC.VOutDate); } if (objRetDC.VOutTime == DateTime.MinValue) { objCmd.Parameters.AddWithValue("@VOutTime", DBNull.Value); } else { objCmd.Parameters.AddWithValue("@VOutTime", objRetDC.VOutTime); } if (objRetDC.IsNew) { objCmd.Parameters.AddWithValue("@StDate", DateTime.Now); objCmd.Parameters.AddWithValue("@CrBy", currentUser.LoginName); //objRetDC.DBID = General.GenerateDBID(Conn, "RETURNABLEDC"); objRetDC.DBID = General.GenerateDBID("SEQDCID", Conn); objRetDC.EntryNo = objRetDC.DBID; } objCmd.Parameters.AddWithValue("@ModifyDate", DateTime.Now); objCmd.Parameters.AddWithValue("@ModBy", currentUser.LoginName); objCmd.Parameters.AddWithValue("@MachineName", General.GetMachineName()); objCmd.Parameters.AddWithValue("@dbID", objRetDC.DBID); objCmd.Parameters.AddWithValue("@EntryNo", objRetDC.EntryNo); if (Conn.State != ConnectionState.Open) { Conn.Open(); } result = objCmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } } return(result > 0); }
/// <summary> /// This method Saves Record into Database. /// </summary> /// <param name="objDCItem">Object containing Data values to be saved.</param> /// <returns>Boolean value True if Record is saved successfully /// otherwise returns False indicating Record is not saved.</returns> public static bool Save(ReturnableDCItem objDCItem, User currentUser) { int result = 0; UserCompany CurrentCompany = new UserCompany(); using (SqlConnection Conn = new SqlConnection(General.GetSQLConnectionString())) { string strSaveQry; if (objDCItem.IsNew) { strSaveQry = "INSERT INTO RETURNABLEDCDETAIL(DBID, ENTRYNO, ENTRYDATE, ENTRYTYPE, " + " DCNO, DCDATE, ITEMCODE, ITEMDESCR, QTY, QTY2, UNIT, REMARK, MASTERDBID, " + " ST_DATE, MODIFY_DATE, CRBY, MODBY, MACHINENAME) " + " VALUES (@dbId, @EntryNo, @EntryDate, @EntryType, @DCNo, @DCDate, " + " @ItemCode, @ItemDescr, @Qty, @Qty2, @Unit, @Remark, @MasterDBID, " + " @STDate, @ModifyDate, @CrBy, @ModBy, @MachineName)"; } else { strSaveQry = "UPDATE RETURNABLEDCDETAIL " + " SET ENTRYNO = @EntryNo, ENTRYDATE = @EntryDate, ENTRYTYPE = @EntryType, " + " DCNO = @DCNo, DCDATE = @DCDate, ITEMCODE = @ItemCode, ITEMDESCR = @ItemDescr" + " Qty = @QTY, QTY2 = @Qty2, UNIT = @Unit, REMARK = @Remark, " + " MASTERDBID = @MasterDBID, MODIFY_DATE = @ModifyDate, " + " MODBY = @ModBy, MACHINENAME = @MachineName " + " WHERE DBID = @dbId"; } try { SqlCommand objCmd = Conn.CreateCommand(); objCmd.CommandType = CommandType.Text; objCmd.CommandText = strSaveQry; objCmd.Parameters.AddWithValue("@EntryNo", objDCItem.EntryNo); objCmd.Parameters.AddWithValue("@EntryDate", objDCItem.EntryDate); objCmd.Parameters.AddWithValue("@EntryType", objDCItem.EntryType); objCmd.Parameters.AddWithValue("@DCNo", objDCItem.DCNo); objCmd.Parameters.AddWithValue("@DCDate", objDCItem.DCDate); objCmd.Parameters.AddWithValue("@ItemCode", objDCItem.ItemCode); objCmd.Parameters.AddWithValue("@ItemDescr", objDCItem.ItemDescr); objCmd.Parameters.AddWithValue("@Qty", objDCItem.Qty); objCmd.Parameters.AddWithValue("@Qty2", objDCItem.Qty2); objCmd.Parameters.AddWithValue("@Unit", objDCItem.UnitName); objCmd.Parameters.AddWithValue("@Remark", objDCItem.Remark); if (objDCItem.IsNew) { objCmd.Parameters.AddWithValue("@StDate", DateTime.Now); objCmd.Parameters.AddWithValue("@CrBy", currentUser.LoginName); //objDCItem.DBID = General.GenerateDBID(Conn, "RETURNABLEDCDETAIL"); objDCItem.DBID = General.GenerateDBID("SEQDCITEMID", Conn); } objCmd.Parameters.AddWithValue("@ModifyDate", DateTime.Now); objCmd.Parameters.AddWithValue("@ModBy", currentUser.LoginName); objCmd.Parameters.AddWithValue("@MachineName", General.GetMachineName()); objCmd.Parameters.AddWithValue("@dbID", objDCItem.DBID); objCmd.Parameters.AddWithValue("@MasterDBID", objDCItem.MasterDBID); if (Conn.State != ConnectionState.Open) { Conn.Open(); } result = objCmd.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception(ex.Message); } } return(result > 0); }
public ActionResult Create(UserViewModel Omodelo) { var OMensaje = new Mensaje(); try { using (RELOJBIOEntities wdb = new RELOJBIOEntities()) { var OUltimoUsuario = wdb.User.OrderByDescending(a => a.UserID).FirstOrDefault(); int wI = OUltimoUsuario.UserID + 1; string wPasswordExpires = "N"; if (Omodelo.PasswordExpires == true) { wPasswordExpires = "S"; } var OUsuario = new User { UserID = wI, FullName = Omodelo.FullName, Login = Omodelo.Login, Password = Omodelo.Password, PasswordExpires = wPasswordExpires, DaysValidity = Omodelo.DaysValidity, LastChangePassword = Omodelo.LastChangePassword, IsActive = Omodelo.IsActive }; wdb.User.Add(OUsuario); wdb.SaveChanges(); //ahora grabo todos los roles foreach (var item in Omodelo.ListRolesCodigoSeleccionados) { var OExisteUserRole = wdb.UserRole.Where(a => a.UserID == OUsuario.UserID && a.RoleID == item).FirstOrDefault(); if (OExisteUserRole == null) { var OUltimoUserRole = wdb.UserRole.OrderByDescending(a => a.UserRoleID).FirstOrDefault(); int wId = OUltimoUserRole.UserRoleID + 1; var OUserRole = new UserRole { UserRoleID = wId, RoleID = item, UserID = OUsuario.UserID }; wdb.UserRole.Add(OUserRole); wdb.SaveChanges(); } } //Grabo las empresas asociadas a ese Usuario foreach (var item in Omodelo.ListCompaniaCodigoSeleccionadas) { var OExisteUserCompani = wdb.UserCompany.Where(a => a.UserID == OUsuario.UserID && a.CompanyID == item).FirstOrDefault(); if (OExisteUserCompani == null) { var OUltimoUserCompani = wdb.UserCompany.OrderByDescending(a => a.UserCompanyID).FirstOrDefault(); int wId = OUltimoUserCompani.UserCompanyID + 1; var OUserCompani = new UserCompany { UserCompanyID = wId, CompanyID = item, UserID = OUsuario.UserID }; wdb.UserCompany.Add(OUserCompani); wdb.SaveChanges(); } } OMensaje.Tipo = "Exito"; OMensaje.Msg = "Usuario Creado con exito"; Session["Mensaje"] = OMensaje; return(RedirectToAction("Index", "Usuario")); } } catch (DbEntityValidationException e) { var errorMessages = e.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage); var fullErrorMessage = string.Join("; ", errorMessages); var exceptionMessage = string.Concat(e.Message, " El error de validacion es: ", fullErrorMessage); OMensaje.Tipo = "Error"; OMensaje.Msg = exceptionMessage; Session["Mensaje"] = OMensaje; return(View(Omodelo)); } }
public HttpResponseMessage IsUnique([FromBody] UserCompany User) { return(requestHandler.ValidateUniqueName(Request, User)); }
public User() { Usercompany = new UserCompany(this); }
public void SelectAndClose(UserWarehouse selectedWarehouse, UserCompany selectedCompany) { if ((selectedWarehouse != null) && (selectedCompany != null)) { try { UserSettingsChangedEventArgs args = new UserSettingsChangedEventArgs(); EventTopic userSettingsTopic = WorkItem.EventTopics.Get(Imi.SupplyChain.UX.UXEventTopicNames.UserSettingsChangedTopic); if (userSettingsTopic != null) { userSettingsTopic.Fire(this, args, WorkItem, PublicationScope.Descendants); if (args.OpenDialogs.Count > 0) { if (ShellInteractionService.ShowMessageBox(this.View.Title, string.Format(LocalResources.ChangeUserSettings_CloseAll, string.Join("\n", args.OpenDialogs)), null, MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { Close(false); return; } } } ShellInteractionService.ShowProgress(); // Get the application IShellModule module = WorkItem.Items.FindByType <IShellModule>().First(); LogonParameters logonParameters = new LogonParameters(); logonParameters.UserIdentity = UserSessionService.UserId; logonParameters.CompanyIdentity = selectedCompany.CompanyIdentity; logonParameters.WarehouseIdentity = selectedCompany.WarehouseIdentity; logonParameters.TerminalIdentity = UserSessionService.TerminalId; logonParameters.ApplicationIdentity = module.Id; LogonRequest logonRequest = new LogonRequest(); logonRequest.LogonParameters = logonParameters; LogonResponse response = Service.Logon(logonRequest); // Set the selected Warehouse and ClientId on statusrow in container ShellInteractionService.ContextInfo = string.Format(LocalResources.STATUSBAR_WH_CLIENT, selectedWarehouse.WarehouseIdentity, selectedWarehouse.WarehouseName, selectedCompany.CompanyIdentity, selectedCompany.CompanyName); Close(true); } catch (Exception ex) { ShellInteractionService.HideProgress(); ShellInteractionService.ShowMessageBox(StringResources.ActionException_Text, ex.Message, ex.ToString(), MessageBoxButton.Ok, MessageBoxImage.Error); } finally { ShellInteractionService.HideProgress(); } } }
/// <summary> /// This method Saves Record into Database. /// </summary> /// <param name="objEmp">Object containing Data values to be saved.</param> /// <returns>Boolean value True if Record is saved successfully /// otherwise returns False indicating Record is not saved.</returns> public static bool Save(Employee objEmp, User objUser) { int result = 0; UserCompany CurrentCompany = new UserCompany(); using (SqlConnection Conn = new SqlConnection(General.GetSQLConnectionString())) { string strSaveQry; if (objEmp.IsNew) { strSaveQry = "INSERT INTO EMPMAST(DBID, EMPCODE, FIRSTNAME, MIDDLENAME, LASTNAME, " + " INITIALS, DEPT, MOBILENO, EMAILID, INACTIVE, " + " EMPPLANT, ST_DATE, MODIFY_DATE, CRBY, MODBY, MACHINENAME) " + " VALUES (@dbId, @EMPCODE, @FIRSTNAME, @MIDDLENAME, @LASTNAME, " + " @INITIALS, @DEPT, @MOBILENO, @EMAILID, @INACTIVE, " + " @EMPPLANT, @STDate, @ModifyDate, @CrBy, @ModBy, @MachineName)"; } else { strSaveQry = "UPDATE EMPMAST " + " SET EMPCODE = @EMPCODE, FIRSTNAME = @FIRSTNAME, MIDDLENAME = @MIDDLENAME, " + " LASTNAME = @LASTNAME, INITIALS = @INITIALS, DEPT = @DEPT, " + " MOBILENO = @MOBILENO, EMAILID = @EMAILID, INACTIVE = @INACTIVE, " + " EMPPLANT = @EMPPLANT, " + " MODIFY_DATE = @ModifyDate, MODBY = @ModBy, MACHINENAME = @MachineName " + " WHERE DBID = @dbId"; } try { SqlCommand objCmd = Conn.CreateCommand(); objCmd.CommandType = CommandType.Text; objCmd.CommandText = strSaveQry; objCmd.Parameters.AddWithValue("@EMPCODE", objEmp.EmpCode); objCmd.Parameters.AddWithValue("@FIRSTNAME", objEmp.FirstName); objCmd.Parameters.AddWithValue("@MIDDLENAME", objEmp.MiddleName); objCmd.Parameters.AddWithValue("@LASTNAME", objEmp.LastName); objCmd.Parameters.AddWithValue("@INITIALS", objEmp.Initials); objCmd.Parameters.AddWithValue("@DEPT", objEmp.DeptID); //objCmd.Parameters.AddWithValue("@JOINDATE", objEmp.JoinDate); //objCmd.Parameters.AddWithValue("@BIRTHDATE", objEmp.BirthDate); //objCmd.Parameters.AddWithValue("@LEFTDATE", objEmp.LeftDate); objCmd.Parameters.AddWithValue("@MOBILENO", objEmp.MobileNo); objCmd.Parameters.AddWithValue("@EMAILID", objEmp.EMailID); objCmd.Parameters.AddWithValue("@INACTIVE", objEmp.InActive); objCmd.Parameters.AddWithValue("@EMPPLANT", objEmp.EmpPlant); if (objEmp.IsNew) { objCmd.Parameters.AddWithValue("@StDate", DateTime.Now); objCmd.Parameters.AddWithValue("@CrBy", objUser.LoginName); //objEmp.DBID = General.GenerateDBID(Conn, "EMPMAST"); objEmp.DBID = General.GenerateDBID("SEQEMPID", Conn); } objCmd.Parameters.AddWithValue("@ModifyDate", DateTime.Now); objCmd.Parameters.AddWithValue("@ModBy", objUser.LoginName); objCmd.Parameters.AddWithValue("@MachineName", General.GetMachineName()); objCmd.Parameters.AddWithValue("@dbID", objEmp.DBID); if (Conn.State != ConnectionState.Open) { Conn.Open(); } result = objCmd.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception(ex.Message); } } return(result > 0); }
/// <summary> /// Fill External Childs of UserCompany Object. /// </summary> /// <param name="userCompanyObject"></param> /// <returns></returns> public void FillChilds(UserCompany userCompanyObject) { ///Fill external information of Childs of UserCompanyObject }
public bool InsertOrUpdate(UserCompany UserCompany) { return(_epr.InsertOrUpdate(UserCompany)); }
/// <summary> /// This method Saves Record into Database. /// </summary> /// <param name="objDept">Object containing Data values to be saved.</param> /// <returns>Boolean value True if Record is saved successfully /// otherwise returns False indicating Record is not saved.</returns> public static bool Save(VehInOut objVehInOut, User objUser) { int result = 0; string strSaveQry; UserCompany CurrentCompany = new UserCompany(); using (SqlConnection Conn = new SqlConnection(General.GetSQLConnectionString())) { //string strSaveQry; if (objVehInOut.IsNew) { //objCmd.CommandText = "INSERT INTO VEHINOUTDETAIL(DBID,ENTRYNO,ENTRYDATE,TYPE," + // " INOUT,INDATE,INTIME,OUTDATE,OUTTIME,VEHNO,DRIVERNAME,CITYNAME," + // " VENDORIN,VENDOROUT,PLANT,ININVCNT,OUTINVCNT,INCARRYMATERIAL, " + // " OUTCARRYMATERIAL,PUCFLG,PUCNO,RCBOOKFLG,RCBOOKNO,FINANCE, " + // " FITNESSFLG,FITNESSNO,DRLICFLG,DRLICNO,PERSONSWITHVEH, " + // " ST_DATE, MODIFY_DATE, CR_BY, MOD_BY, MACHINENAME, INREADING, OUTREADING) " + // " VALUES (" + objVehInOut.Dbid + "," + // " " + objVehInOut.EntryNo + "," + // " '" + objVehInOut.EntryDate.ToString("dd-MMM-yy") + "'," + // " " + objVehInOut.Type + "," + // " " + objVehInOut.InOut + "," + // " '" + objVehInOut.InDate.ToString("dd-MMM-yy") + "'," + // " '" + objVehInOut.InTime.ToShortTimeString() + "'," + // " '" + objVehInOut.OutDate.ToString("dd-MMM-yy") + "'," + // " '" + objVehInOut.OutTime.ToShortTimeString() + "'," + // " '" + objVehInOut.VehNo + "'," + // " '" + objVehInOut.DriverName + "'," + // " '" + objVehInOut.CityName + "'," + // " '" + objVehInOut.VendorIn + "'," + // " '" + objVehInOut.VendorOut + "'," + // " '" + objVehInOut.Plant + "'," + // " " + objVehInOut.InInvCnt + "," + // " " + objVehInOut.OutInvCnt + "," + // " '" + objVehInOut.InCarryMaterial + "'," + // " '" + objVehInOut.OutCarryMaterial + "'," + // " '" + objVehInOut.PUCFlg + "'," + // " '" + objVehInOut.PUCNo + "'," + // " '" + objVehInOut.RCBookFlg + "'," + // " '" + objVehInOut.RCBookNo + "'," + // " '" + objVehInOut.Finance + "'," + // " '" + objVehInOut.FitnessFlg + "'," + // " '" + objVehInOut.FitnessNo + "'," + // " '" + objVehInOut.DrLicFlg + "'," + // " '" + objVehInOut.DrLicNo + "'," + // " " + objVehInOut.PersonsWithVeh + "," + // " '" + DateTime.Now.ToString("dd-MMM-yy") + "'," + // " '" + DateTime.Now.ToString("dd-MMM-yy") + "'," + // " '" + CurrentCompany.m_UserName + "'," + // " '" + CurrentCompany.m_UserName + "'," + // " '" + System.Environment.MachineName + "'," + objVehInOut.InReading + "," + objVehInOut.OutReading + ")"; strSaveQry = "INSERT INTO VEHINOUTDETAIL(DBID, ENTRYNO, ENTRYDATE, TYPE, " + " INOUT, INDATE, INTIME, OUTDATE, OUTTIME, VEHNO, DRIVERNAME, CITYNAME," + " VENDORIN, VENDOROUT, PLANT, ININVCNT, OUTINVCNT, INCARRYMATERIAL, " + " OUTCARRYMATERIAL, PUCFLG, PUCNO, RCBOOKFLG, RCBOOKNO, FINANCE, " + " FITNESSFLG, FITNESSNO, DRLICFLG, DRLICNO, PERSONSWITHVEH, " + " ST_DATE, MODIFY_DATE, CR_BY, MOD_BY, MACHINENAME, INREADING, OUTREADING) " + " VALUES (@DBID, @ENTRYNO, @ENTRYDATE, @TYPE, " + " @INOUT, @INDATE, @INTIME, @OUTDATE, @OUTTIME, @VEHNO, @DRIVERNAME, @CITYNAME, " + " @VENDORIN, @VENDOROUT, @PLANT, @ININVCNT, @OUTINVCNT, @INCARRYMATERIAL," + " @OUTCARRYMATERIAL, @PUCFLG, @PUCNO, @RCBOOKFLG, @RCBOOKNO, @FINANCE, " + " @FITNESSFLG, @FITNESSNO, @DRLICFLG, @DRLICNO, @PERSONSWITHVEH, " + " @STDATE, @ModifyDate, @CrBy, @ModBy, @MachineName, @INREADING, @OUTREADING)"; } else { //objCmd.CommandText = "UPDATE VEHINOUTDETAIL " + // "SET ENTRYNO =" + objVehInOut.EntryNo + "," + // " ENTRYDATE ='" + objVehInOut.EntryDate.ToString("dd-MMM-yy") + "'," + // " TYPE =" + objVehInOut.Type + "," + // " INOUT = " + objVehInOut.InOut + "," + // " INDATE ='" + objVehInOut.InDate.ToString("dd-MMM-yy") + "'," + // " INTIME ='" + objVehInOut.InTime.ToShortTimeString() + "'," + // " OUTDATE ='" + objVehInOut.OutDate.ToString("dd-MMM-yy") + "'," + // " OUTTIME ='" + objVehInOut.OutTime.ToShortTimeString() + "'," + // " VEHNO ='" + objVehInOut.VehNo + "'," + // " DRIVERNAME = '" + objVehInOut.DriverName + "'," + // " CITYNAME = '" + objVehInOut.CityName + "'," + // " VENDORIN = '" + objVehInOut.VendorIn + "'," + // " VENDOROUT = '" + objVehInOut.VendorIn + "'," + // " PLANT ='" + objVehInOut.Plant + "'," + // " ININVCNT = " + objVehInOut.InInvCnt + "," + // " OUTINVCNT = " + objVehInOut.OutInvCnt + "," + // " INCARRYMATERIAL = '" + objVehInOut.InCarryMaterial + "'," + // " OUTCARRYMATERIAL = '" + objVehInOut.OutCarryMaterial + "'," + // " PUCFLG = '" + objVehInOut.PUCFlg + "'," + // " PUCNO ='" + objVehInOut.PUCNo + "'," + // " RCBOOKFLG = '" + objVehInOut.RCBookFlg + "'," + // " RCBOOKNO = '" + objVehInOut.RCBookNo + "'," + // " FINANCE = '" + objVehInOut.Finance + "'," + // " FITNESSFLG ='" + objVehInOut.FitnessFlg + "'," + // " FITNESSNO = '" + objVehInOut.FitnessNo + "'," + // " DRLICFLG = '" + objVehInOut.DrLicFlg + "'," + // " DRLICNO = '" + objVehInOut.DrLicNo + "'," + // " PERSONSWITHVEH = " + objVehInOut.PersonsWithVeh + "," + // " MODIFY_DATE = '" + DateTime.Now.ToString("dd-MMM-yy") + "'," + // " MOD_BY = '" + CurrentCompany.m_UserName + "'," + // " MACHINENAME ='" + System.Environment.MachineName + "'," + // " INREADING = " + objVehInOut.InReading + ", " + // " OUTREADING = " + objVehInOut.OutReading + // " WHERE DBID = " + objVehInOut.Dbid + ""; strSaveQry = "UPDATE VEHINOUTDETAIL " + "SET ENTRYNO = @ENTRYNO , ENTRYDATE = @ENTRYDATE, TYPE = @TYPE, INOUT = @INOUT, " + " INDATE = @INDATE , INTIME = @INTIME , OUTDATE = @OUTDATE , OUTTIME = @OUTTIME , " + " VEHNO = @VEHNO , DRIVERNAME = @DRIVERNAME , CITYNAME = @CITYNAME , VENDORIN = @VENDORIN , " + " VENDOROUT = @VENDOROUT , PLANT = @PLANT, ININVCNT = @ININVCNT, OUTINVCNT = @OUTINVCNT , " + " INCARRYMATERIAL = @INCARRYMATERIAL, OUTCARRYMATERIAL = @OUTCARRYMATERIAL , PUCFLG = @PUCFLG , " + " PUCNO = @PUCNO , RCBOOKFLG = @RCBOOKFLG , RCBOOKNO = @RCBOOKNO, FINANCE = @FINANCE, " + " FITNESSFLG = @FITNESSFLG, FITNESSNO = @FITNESSNO , DRLICFLG = @DRLICFLG , DRLICNO =@DRLICNO , " + " PERSONSWITHVEH = @PERSONSWITHVEH , MODIFY_DATE = @MODIFYDATE, MOD_BY = @MODBY, " + " MACHINENAME = @MACHINENAME, INREADING = @INREADING, OUTREADING = @OUTREADING " + " WHERE DBID = @DBID"; } try { SqlCommand objCmd = Conn.CreateCommand(); objCmd.CommandType = CommandType.Text; objCmd.CommandText = strSaveQry; //objCmd.Parameters.AddWithValue("@ENTRYNO", objVehInOut.EntryNo); //objCmd.Parameters.AddWithValue("@ENTRYDATE", objVehInOut.EntryDate.ToShortDateString()); objCmd.Parameters.AddWithValue("@TYPE", objVehInOut.Type); objCmd.Parameters.AddWithValue("@INOUT", objVehInOut.InOut); if (objVehInOut.InDate != DateTime.MinValue) { objCmd.Parameters.AddWithValue("@INDATE", objVehInOut.InDate); } else { objCmd.Parameters.AddWithValue("@INDATE", DBNull.Value); } if (objVehInOut.InTime != DateTime.MinValue) { objCmd.Parameters.AddWithValue("@INTIME", objVehInOut.InTime); } else { objCmd.Parameters.AddWithValue("@INTIME", DBNull.Value); } if (objVehInOut.OutDate != DateTime.MinValue) { objCmd.Parameters.AddWithValue("@OUTDATE", objVehInOut.OutDate); } else { objCmd.Parameters.AddWithValue("@OUTDATE", DBNull.Value); } if (objVehInOut.OutTime != DateTime.MinValue) { objCmd.Parameters.AddWithValue("@OUTTIME", objVehInOut.OutTime); } else { objCmd.Parameters.AddWithValue("@OUTTIME", DBNull.Value); } objCmd.Parameters.AddWithValue("@VEHNO", objVehInOut.VehNo); objCmd.Parameters.AddWithValue("@DRIVERNAME", objVehInOut.DriverName); objCmd.Parameters.AddWithValue("@CITYNAME", objVehInOut.CityName); objCmd.Parameters.AddWithValue("@VENDORIN", objVehInOut.VendorIn); objCmd.Parameters.AddWithValue("@VENDOROUT", objVehInOut.VendorOut); objCmd.Parameters.AddWithValue("@PLANT", objVehInOut.Plant); objCmd.Parameters.AddWithValue("@ININVCNT", objVehInOut.InInvCnt); objCmd.Parameters.AddWithValue("@OUTINVCNT", objVehInOut.OutInvCnt); objCmd.Parameters.AddWithValue("@INCARRYMATERIAL", objVehInOut.InCarryMaterial); objCmd.Parameters.AddWithValue("@OUTCARRYMATERIAL", objVehInOut.OutCarryMaterial); objCmd.Parameters.AddWithValue("@PUCFLG", objVehInOut.PUCFlg); objCmd.Parameters.AddWithValue("@PUCNO", objVehInOut.PUCNo); objCmd.Parameters.AddWithValue("@RCBOOKFLG", objVehInOut.RCBookFlg); objCmd.Parameters.AddWithValue("@RCBOOKNO", objVehInOut.RCBookNo); objCmd.Parameters.AddWithValue("@FINANCE", objVehInOut.Finance); objCmd.Parameters.AddWithValue("@FITNESSFLG", objVehInOut.FitnessFlg); objCmd.Parameters.AddWithValue("@FITNESSNO", objVehInOut.FitnessNo); objCmd.Parameters.AddWithValue("@DRLICFLG", objVehInOut.DrLicFlg); objCmd.Parameters.AddWithValue("@DRLICNO", objVehInOut.DrLicNo); objCmd.Parameters.AddWithValue("@PERSONSWITHVEH", objVehInOut.PersonsWithVeh); if (objVehInOut.IsNew) { objVehInOut.EntryDate = DateTime.Now.Date; //objVehInOut.Dbid = General.GenerateDBID(Conn, "VEHINOUTDETAIL"); objVehInOut.Dbid = General.GenerateDBID("SEQVEHINOUTID", Conn); objVehInOut.EntryNo = objVehInOut.Dbid; objCmd.Parameters.AddWithValue("@STDATE", DateTime.Now); objCmd.Parameters.AddWithValue("@CRBY", objUser.LoginName); //CurrentCompany.m_UserName } objCmd.Parameters.AddWithValue("@DBID", objVehInOut.Dbid); objCmd.Parameters.AddWithValue("@ENTRYNO", objVehInOut.EntryNo); objCmd.Parameters.AddWithValue("@ENTRYDATE", objVehInOut.EntryDate); objCmd.Parameters.AddWithValue("@MODIFYDATE", DateTime.Now); objCmd.Parameters.AddWithValue("@MODBY", objUser.LoginName); //CurrentCompany.m_UserName objCmd.Parameters.AddWithValue("@MACHINENAME", General.GetMachineName()); objCmd.Parameters.AddWithValue("@INREADING", objVehInOut.InReading); objCmd.Parameters.AddWithValue("@OUTREADING", objVehInOut.OutReading); if (Conn.State != ConnectionState.Open) { Conn.Open(); } result = objCmd.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception(ex.Message); } finally { Conn.Close(); } Conn.Dispose(); } return(result > 0); }
public IActionResult AddUserCompany([FromBody] UserCompany model) { UserCompany_repo.Add(model); return(new OkObjectResult(new { UserCompanyID = model.UserCompanyId })); }
public SessionServer(Id id, SessionToken sessionToken, UserCompany userCompany) { Id = id; SessionToken = sessionToken; UserCompany = userCompany; }
public IActionResult UpdateHrUserCompany([FromBody] UserCompany model) { UserCompany_repo.Update(model); return(new OkObjectResult(new { UserCompanylID = model.UserCompanyId })); }
private void saveuserstaffdata(HttpContext context) { int UserID = WebUtil.GetIntValue(context, "UserID"); Foresight.DataAccess.User data = null; if (UserID > 0) { data = Foresight.DataAccess.User.GetUser(UserID); } if (data == null) { data = new User(); data.CreateTime = DateTime.Now; data.Type = UserTypeDefine.APPUser.ToString(); } data.LoginName = WebUtil.getServerValue(context, "tdLoginName"); string Password = WebUtil.getServerValue(context, "tdPassword"); if (!string.IsNullOrEmpty(Password)) { data.Password = User.EncryptPassword(Password); } data.RealName = WebUtil.getServerValue(context, "tdRealName"); data.PhoneNumber = WebUtil.getServerValue(context, "tdPhoneNumber"); data.Gender = WebUtil.getServerValue(context, "tdGender"); bool IsLocked = WebUtil.getServerIntValue(context, "tdIsLocked") == 1; if (IsLocked && !data.IsLocked) { data.LockTime = DateTime.Now; } if (!IsLocked && data.IsLocked) { data.ActiveTime = DateTime.Now; } data.IsLocked = IsLocked; int OrgID = WebUtil.getServerIntValue(context, "tdDepartment"); UserDepartment org = null; if (OrgID > 0 && !data.Type.Equals(UserTypeDefine.SystemUser.ToString())) { org = UserDepartment.GetUserDepartment(UserID, OrgID); if (org == null) { org = new UserDepartment(); org.DepartmentID = OrgID; } } data.ServiceFrom = WebUtil.getServerValue(context, "tdServiceFrom"); data.PositionName = WebUtil.getServerValue(context, "tdPositionName"); using (SqlHelper helper = new SqlHelper()) { try { helper.BeginTransaction(); data.Save(helper); if (org != null) { org.UserID = data.UserID; org.Save(helper); var parameters = new List <SqlParameter>(); parameters.Add(new SqlParameter("@UserID", data.UserID)); parameters.Add(new SqlParameter("@DepartmentID", org.DepartmentID)); helper.Execute("delete from [UserDepartment] where [UserID]=@UserID and [DepartmentID]!=@DepartmentID", CommandType.Text, parameters); } var userCompany = UserCompany.GetUserCompanyByUserID(data.UserID); if (userCompany == null) { userCompany = new UserCompany(); userCompany.UserID = data.UserID; userCompany.CompanyID = 1; userCompany.Save(helper); } helper.Commit(); } catch (Exception ex) { helper.Rollback(); LogHelper.WriteError("SysSettingHandler", "saveuserdata", ex); WebUtil.WriteJson(context, new { status = false, error = ex.Message }); return; } } WebUtil.WriteJson(context, new { status = true }); }
public UserCompany Add(UserCompany userCompany) { _entity.Add(userCompany); _context.SaveChanges(); return(userCompany); }
public static void FormAuthenticate(string frmName, UserCompany objCompany, User objUser) { frmAddRight = false; frmModifyRight = false; frmViewRight = false; frmDeleteRight = false; repView = false; repPrintRight = false; string rMenuKey = string.Empty; switch (frmName) { case "frmDeptList": rMenuKey = "D0011"; break; case "frmEmployeeList": rMenuKey = "D0012"; break; case "frmVisitorList": rMenuKey = "D0013"; break; case "frmCityList": rMenuKey = "D0014"; break; case "frmDriverList": rMenuKey = "D0015"; break; case "frmVehicleList": rMenuKey = "D0016"; break; case "frmUserList": rMenuKey = "D0017"; break; case "frmVehInOutList": rMenuKey = "T0011"; break; case "frmAppointmentList": rMenuKey = "T0012"; break; case "frmVisitorGPList": rMenuKey = "T0013"; break; case "frmReturnableDCList": rMenuKey = "T0014"; break; case "frmUserAuthority": rMenuKey = "U0011"; break; } if (rMenuKey != string.Empty) { string[] strRightList = UserRightsManager.GetUserFormRights(objUser.DBID, rMenuKey); if (strRightList != null) { foreach (string strRight in strRightList) { if (strRight == rMenuKey + "A") { frmAddRight = true; } else if (strRight == rMenuKey + "M") { frmModifyRight = true; } else if (strRight == rMenuKey + "V") { frmViewRight = true; } else if (strRight == rMenuKey + "D") { frmDeleteRight = true; } else if (strRight == rMenuKey + "P") { repPrintRight = true; } } } } }
public bool Save(UserCompany UserCompany) { _UserCompanyApp.InsertOrUpdate(UserCompany); return(_connection.Save()); }
public async Task <ActionResult <UserCompany> > AddUserToCompanyAsync(UserCompany userCompany) { await _companyService.AddUserToCompanyAsync(userCompany); return(Ok(userCompany)); }
/// <summary> /// This method Saves Record into Database. /// </summary> /// <param name="objDept">Object containing Data values to be saved.</param> /// <returns>Boolean value True if Record is saved successfully /// otherwise returns False indicating Record is not saved.</returns> public static bool Save(Vehicle objVehicle, User objUser) { int result = 0; UserCompany CurrentCompany = new UserCompany(); using (SqlConnection Conn = new SqlConnection(General.GetSQLConnectionString())) { string strSaveQry; if (objVehicle.IsNew) { strSaveQry = "INSERT INTO VEHICLEMASTER(DBID, VEHICLENO, VLICENSENO,PUCEXPIRY,ISACTIVE, " + " ST_DATE, MODIFY_DATE, CRBY, MODBY, MACHINENAME) " + "VALUES (@dbId, @VehicleNo, @VLicencseNo,@PUCExpiry, @IsActive, " + " @STDate, @ModifyDate, @CrBy, @ModBy, @MachineName)"; } else { strSaveQry = "UPDATE VEHICLEMASTER " + "SET VEHICLENO = @VehicleNo, VLICENSENO = @VLicencseNo,PUCEXPIRY = @PUCExpiry, ISACTIVE = @IsActive, " + "MODIFY_DATE = @ModifyDate, MODBY = @ModBy, MACHINENAME = @MachineName " + "WHERE DBID = @dbId"; } try { SqlCommand objCmd = Conn.CreateCommand(); objCmd.CommandType = CommandType.Text; objCmd.CommandText = strSaveQry; objCmd.Parameters.AddWithValue("@VehicleNo", objVehicle.VehicleNo); objCmd.Parameters.AddWithValue("@VLicencseNo", objVehicle.VLicencseNo); if (objVehicle.PUCExpiry != DateTime.MinValue) { objCmd.Parameters.AddWithValue("@PUCExpiry", objVehicle.PUCExpiry); } else { objCmd.Parameters.AddWithValue("@PUCExpiry", DBNull.Value); } objCmd.Parameters.AddWithValue("@IsActive", objVehicle.IsActive); if (objVehicle.IsNew) { objCmd.Parameters.AddWithValue("@StDate", DateTime.Now); objCmd.Parameters.AddWithValue("@CrBy", objUser.LoginName); objVehicle.Dbid = General.GenerateDBID(Conn, "VEHICLEMASTER"); } objCmd.Parameters.AddWithValue("@ModifyDate", DateTime.Now); objCmd.Parameters.AddWithValue("@ModBy", objUser.LoginName); objCmd.Parameters.AddWithValue("@MachineName", General.GetMachineName()); objCmd.Parameters.AddWithValue("@dbID", objVehicle.Dbid); if (Conn.State != ConnectionState.Open) { Conn.Open(); } result = objCmd.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception(ex.Message); } } return(result > 0); }
public static RegisterViewModel Detach(UserCompany company) { RegisterViewModel registerViewModel = new RegisterViewModel(); return(registerViewModel); }
private void saveapppwd(HttpContext context) { int RelationID = GetIntValue(context, "RelationID"); var relation = RoomPhoneRelation.GetRoomPhoneRelation(RelationID); if (relation == null) { WebUtil.WriteJson(context, new { status = false, errormsg = "房间用户不存在" }); return; } string LoginName = context.Request.Params["LoginName"]; string Pwd = context.Request.Params["Password"]; int IsLocked = WebUtil.GetIntValue(context, "IsLocked"); User user = null; if (relation.UserID > 0) { user = User.GetUser(relation.UserID); } var exist_user = User.GetAPPUserByLoginName(LoginName); if (user == null && exist_user != null) { WebUtil.WriteJson(context, new { status = false, errormsg = "登录名已存在" }); return; } if (user != null && exist_user != null && user.UserID != exist_user.UserID) { WebUtil.WriteJson(context, new { status = false, errormsg = "登录名已存在" }); return; } if (user == null) { user = new User(); user.CreateTime = DateTime.Now; user.Type = UserTypeDefine.APPCustomer.ToString(); user.RealName = relation.RelationName; user.RelationID = RelationID; } user.LoginName = LoginName; if (!string.IsNullOrEmpty(Pwd)) { user.Password = User.EncryptPassword(Pwd); } user.IsLocked = IsLocked == 1 ? true : false; using (SqlHelper helper = new SqlHelper()) { try { helper.BeginTransaction(); user.Save(helper); relation.UserID = user.UserID; relation.Save(helper); helper.Commit(); } catch (Exception ex) { helper.Rollback(); LogHelper.WriteError("UserHandler", "saveapppwd", ex); WebUtil.WriteJson(context, new { status = false }); } } var company = Foresight.DataAccess.Company.GetCompany(WebUtil.GetCompanyID(context)); string errormsg = string.Empty; if (!EncryptHelper.SaveAPPUser(company, user.LoginName, user.Password, user.UserID, user.Type, out errormsg)) { user.Delete(); relation.UserID = 0; relation.Save(); var result = new { status = false, msg = errormsg }; WebUtil.WriteJson(context, result); return; } var usercompany = Foresight.DataAccess.UserCompany.GetUserCompanyByUserID(user.UserID); if (usercompany != null) { usercompany.Delete(); } usercompany = new UserCompany(); usercompany.CompanyID = company.CompanyID; usercompany.UserID = user.UserID; usercompany.Save(); context.Response.Write("{\"status\":true}"); }
public HttpResponseMessage Get([FromBody] UserCompany data) { return(requestHandler.GetGbObjects(Request, data)); }
private void SaveUserInfo(HttpContext context) { bool new_user_add = false; string UserType = context.Request["UserType"]; UserType = string.IsNullOrEmpty(UserType) ? UserTypeDefine.SystemUser.ToString() : UserType; int UserID = GetIntValue(context, "UserID"); int CompanyID = GetIntValue(context, "CompanyID"); CompanyID = CompanyID <= 0 ? WebUtil.GetCompanyID(context) : CompanyID; Foresight.DataAccess.User user = null; Foresight.DataAccess.Company company = null; int isLocked = GetIntValue(context, "IsLocked"); bool IsAllowSysLogin = WebUtil.GetIntValue(context, "IsAllowSysLogin") == 1; int user_type = WebUtil.GetIntValue(context, "user_type"); if (UserID > 0) { user = User.GetUser(UserID); } if (user == null || isLocked == 0) { if (UserType.Equals(UserTypeDefine.SystemUser.ToString()) || IsAllowSysLogin) { company = WebUtil.GetCompany(context, false); int userCount = company.UserCount; int TotalCount = Foresight.DataAccess.User.GetSysUserCount(); if (user == null || (user != null && user.IsLocked)) { TotalCount = TotalCount + 1; } if (TotalCount > userCount) { WebUtil.WriteJson(context, new { status = true, addfailed = true }); return; } } } if (user == null) { new_user_add = true; user = new User(); user.CreateTime = DateTime.Now; } string LoginName = context.Request.Params["LoginName"]; if (UserType.Equals(UserTypeDefine.SystemUser.ToString())) { var sameuser = Foresight.DataAccess.User.GetUserByLoginName(LoginName); if (sameuser != null && sameuser.UserID != user.UserID) { WebUtil.WriteJson(context, new { status = false, error = "登录名已存在" }); return; } } else { var sameuser = Foresight.DataAccess.User.GetAPPUserByLoginName(LoginName); if (sameuser != null && sameuser.UserID != user.UserID) { if (UserType.Equals(Foresight.DataAccess.UserTypeDefine.APPUser.ToString()) && sameuser.Type.Equals(UserTypeDefine.APPCustomer.ToString())) { user = sameuser; } else { WebUtil.WriteJson(context, new { status = false, error = "登录名已存在" }); return; } } } if (user_type <= 0 || new_user_add) { user.Type = UserType; } user.NickName = context.Request.Params["NickName"]; user.RealName = context.Request.Params["RealName"]; user.PhoneNumber = context.Request.Params["PhoneNumber"]; user.Gender = context.Request.Params["Gender"]; user.IsLocked = isLocked == 0 ? false : true; if (user.IsLocked) { user.LockTime = DateTime.Now; } if (!user.IsLocked) { user.ActiveTime = DateTime.Now; } string Pwd = context.Request.Params["Password"]; user.LoginName = LoginName; if (!string.IsNullOrEmpty(Pwd)) { user.Password = User.EncryptPassword(Pwd); } user.IsAllowSysLogin = IsAllowSysLogin; user.IsAllowAPPUserLogin = WebUtil.GetIntValue(context, "IsAllowAPPUserLogin") == 1; user.HotPhoneLine = context.Request.Params["HotPhoneLine"]; user.BelongServiceName = context.Request.Params["BelongServiceName"]; user.QQNumber = context.Request.Params["QQNumber"]; user.OpenID = context.Request.Params["OpenID"]; user.PositionName = context.Request["PositionName"]; user.Education = context.Request["Education"]; user.DepartmentID = WebUtil.GetIntValue(context, "DepartmentID"); user.FixedPoint = WebUtil.GetIntValue(context, "FixedPoint"); user.FixedPointUpdateDate = WebUtil.GetDateValue(context, "FixedPointUpdateDate"); user.IsAllowPhrase = WebUtil.GetIntValue(context, "IsAllowPhrase") == 1; string DepartmentIDs = context.Request["DepartmentIDList"]; int[] DepartmentIDList = new int[] { }; if (!string.IsNullOrEmpty(DepartmentIDs)) { DepartmentIDList = Utility.JsonConvert.DeserializeObject <int[]>(DepartmentIDs); } UserDepartment[] userDepartmentList = new UserDepartment[] { }; if (user.UserID > 0) { userDepartmentList = UserDepartment.GetUserDepartmentListByMinMaxUserID(user.UserID, user.UserID); } using (SqlHelper helper = new SqlHelper()) { try { helper.BeginTransaction(); user.Save(helper); foreach (var item in userDepartmentList) { item.Delete(helper); } foreach (var DepartmentID in DepartmentIDList) { var data = new UserDepartment(); data.UserID = user.UserID; data.DepartmentID = DepartmentID; data.Save(helper); } var usercompany = Foresight.DataAccess.UserCompany.GetUserCompanyByUserID(user.UserID, helper); if (usercompany == null) { usercompany = new UserCompany(); usercompany.CompanyID = CompanyID; } usercompany.UserID = user.UserID; usercompany.Save(helper); helper.Commit(); } catch (Exception) { helper.Rollback(); WebUtil.WriteJson(context, new { status = false }); } } //if (UserType.Equals(UserTypeDefine.APPUser.ToString())) //{ // company = Foresight.DataAccess.Company.GetCompanies().FirstOrDefault(); // string errormsg = string.Empty; // if (!EncryptHelper.SaveAPPUser(company, user.LoginName, user.Password, user.UserID, user.Type, out errormsg)) // { // user.Delete(); // WebUtil.WriteJson(context, new { status = false, error = errormsg }); // return; // } //} if (new_user_add) { #region 新增账号日志 APPCode.CommHelper.SaveOperationLog("新增账号" + user.LoginName, Utility.EnumModel.OperationModule.AddUser.ToString(), "新增账号", user.UserID.ToString(), "User"); #endregion } WebUtil.WriteJson(context, new { status = true }); }
public HttpResponseMessage Delete([FromBody] UserCompany User) { return(requestHandler.DeleteGbObject(Request, User)); }
/// <summary> /// /// </summary> /// <param name="studentDetails"></param> /// <param name="userCompany"></param> /// <returns></returns> public bool IsMyStudent(string studentDetails, UserCompany userCompany, int userId, int companyId, bool EnabledUsersOnly = true, bool DirectSupervisionUsersOnly = false, string altStudentQuery = "", bool RequiresCompanyManagePerm = true, bool RequireIsVisible = true) { int userDetails = 0, studentCount = 0; try { //validate if (!Validator.Valid(studentDetails, typeof(DatabaseWrapper)) && altStudentQuery == "") { throw new ArgumentException("student list"); } if (!Validator.Valid(altStudentQuery, typeof(string)) && studentDetails == "") { throw new ArgumentException("alt Student Query"); } if (studentDetails == "") { studentCount = Validator.GetInt(ExecuteScalar(string.Format("select count(*) from ( {0} ) T1;", altStudentQuery))); } else { studentCount = studentDetails.Split(',').Length; } if (userDetails == Validator.GetInt(studentDetails)) { return(true); } else { List <int> students = studentDetails.Split(',').Select(int.Parse).ToList(); using (DBEntity dBEntity = new DBEntity()) { IQueryable <int> isMyStudent = (from uc in dBEntity.UserCompany join ucm in dBEntity.UserCompany on uc.CompanyId equals ucm.CompanyId where ucm.UserId == userId && ucm.CompanyPerms == (int)CompanyPerms.Edit && ucm.IsEnabled && ucm.Status == 1 && uc.CompanyId == companyId && uc.IsVisible && uc.IsEnabled && students.Contains(uc.UserId) select uc.UserId); if ((userCompany.ReportsPerms & (int)ReportPerms.CrossCompanyReports) == (int)ReportPerms.CrossCompanyReports) { IQueryable <int> isMyCrossStudent = (from uc in dBEntity.UserCompany join cc in dBEntity.CompanyClient on uc.CompanyId equals cc.ClientCompany join ucm in dBEntity.UserCompany on cc.OwnerCompany equals ucm.CompanyId where ucm.UserId == userId && ucm.CompanyPerms == (int)CompanyPerms.Edit && ucm.IsEnabled && ucm.Status == 1 && ucm.CompanyId == companyId && students.Contains(uc.UserId) && uc.IsVisible && uc.IsEnabled && uc.IsVisible && uc.Status == 1 select uc.UserId); isMyStudent = isMyStudent.Union(isMyCrossStudent); } bool result = isMyStudent.Count() > 0; return(result); } } } catch (Exception studentException) { LambdaLogger.Log(studentException.ToString()); return(false); } }