public DataResponse <EntityProfile> GetUserDeviceIdById(int UserId) { DataResponse <EntityProfile> response = new DataResponse <EntityProfile>(); try { base.DBInit(); var query = DBEntity.UserProfiles.Where(a => a.UserId == UserId).FirstOrDefault(); var entity = new EntityProfile { Id = query.UserId.Value, DeviceId = query.DeviceId }; if (query != null) { response.CreateResponse(entity, DataResponseStatus.OK); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { response.ThrowError(ex); } finally { base.DBClose(); } return(response); }
public DataResponse <EntityList <T> > GetList <T>(IQueryable <T> query) { //int count = query.Count(); DataResponse <EntityList <T> > response = new DataResponse <EntityList <T> >(); EntityList <T> entity = new EntityList <T>(); try { entity.Pager = new DataPager { TotalCount = query.Count() }; entity.List = query.ToList(); if (entity.List == null) { response.CreateResponse(null, DataResponseStatus.NoContent); } else { response.CreateResponse(entity, DataResponseStatus.OK); } } catch (Exception ex) { //ex.Log(); response.ThrowError(ex); } return(response); }
public DataResponse <EntityList <T> > GetList <T>(IEnumerable <T> query, int skip, int take) { //int count = query.Count(); DataResponse <EntityList <T> > response = new DataResponse <EntityList <T> >(); EntityList <T> entity = new EntityList <T>(); try { entity.Pager = new DataPager { TotalCount = query.Count(), Skip = skip, Take = take }; entity.List = query.Skip(skip).Take(take).ToList(); if (entity.List == null) { response.CreateResponse(null, DataResponseStatus.NoContent); } else { response.CreateResponse(entity, DataResponseStatus.OK); } } catch (Exception ex) { response.ThrowError(ex); } return(response); }
public DataResponse <EntityDocumentTypes> Insert(EntityDocumentTypes entity) { var response = new DataResponse <EntityDocumentTypes>(); try { base.DBInit(); var model = new Database.LookupDocumentType { DocumentType = entity.DocumentType, BusinessId = entity.BusinessId, CreatedOn = entity.CreatedOn, CreatedBy = entity.CreatedBy }; if (base.DBSave(model) > 0) { entity.Id = model.Id; response.CreateResponse(entity, DataResponseStatus.OK); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { ex.Log(); } finally { base.DBClose(); } return(response); }
public DataResponse <EntityColumnLookup> InsertReportColumnLookup(EntityColumnLookup entity) { var response = new DataResponse <EntityColumnLookup>(); try { base.DBInit(); var model = new Database.LookupServiceColumn { Text = entity.Text, ColumnId = entity.ColumnId, CreatedBy = entity.CreatedBy, CreatedOn = System.DateTime.UtcNow }; if (base.DBSave(model) > 0) { entity.Id = model.Id; response.CreateResponse(entity, DataResponseStatus.OK); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { ex.Log(); } finally { base.DBClose(); } return(response); }
public DataResponse UpdateNotificationPushStatus(long id, long userId) { var response = new DataResponse(); try { DBInit(); var model = DBEntity.NotificationUsers.Where(t => t.NotificationId == id).FirstOrDefault(); model.IsPushSent = true; var rowCount = DBSaveUpdate(model); if (rowCount > 0) { response.CreateResponse(DataResponseStatus.OK); } else { response.CreateResponse(DataResponseStatus.NotModified); } } catch (Exception ex) { ex.Log(); } finally { DBClose(); } return(response); }
public DataResponse <EntityRepGroups> Insert(EntityRepGroups entity) { var response = new DataResponse <EntityRepGroups>(); try { base.DBInit(); var model = new Database.RepGroup { BusinessId = entity.BusinessId, RepGroupName = entity.RepGroupName, Description = entity.Description, CreatedBy = entity.CreatedBy, CreatedOn = entity.CreatedOn, IsActive = true, //SalesDirectorId = entity.SalesDirectorId, }; if (base.DBSave(model) > 0) { if (entity.SalesDirectorIds != null && entity.SalesDirectorIds.Count() > 0) { foreach (var item in entity.SalesDirectorIds) { DBEntity.RepgroupManagerMappers.Add(new RepgroupManagerMapper { RepGroupId = model.Id, ManagerId = item, UserRole = (int)RepgroupUserType.Director, CreatedBy = entity.CreatedBy, CreatedOn = entity.CreatedOn }); DBEntity.SaveChanges(); } } if (entity.RepGroupManagerIds != null && entity.RepGroupManagerIds.Count() > 0) { foreach (var item in entity.RepGroupManagerIds) { DBEntity.RepgroupManagerMappers.Add(new RepgroupManagerMapper { RepGroupId = model.Id, ManagerId = item, UserRole = (int)RepgroupUserType.Manager, CreatedBy = entity.CreatedBy, CreatedOn = entity.CreatedOn }); DBEntity.SaveChanges(); } } entity.Id = model.Id; response.CreateResponse(entity, DataResponseStatus.OK); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { ex.Log(); } finally { base.DBClose(); } return(response); }
public DataResponse <EntityRoles> Insert(EntityRoles entity) { var response = new DataResponse <EntityRoles>(); try { base.DBInit(); var model = new Database.Role { Name = entity.Name, Description = entity.Description, BusinessId = entity.BusinessId, Status = 1, IsActive = true, CreatedOn = entity.CreatedOn, CreatedBy = entity.CreatedBy }; if (base.DBSave(model) > 0) { if (entity.RolePrivilegeIds != null && entity.RolePrivilegeIds.Count() > 0) { foreach (var item in entity.RolePrivilegeIds) { DBEntity.RolePrivileges.Add(new RolePrivilege { RoleId = model.Id, PrivilegeId = item, CreatedBy = entity.CreatedBy.Value, CreatedOn = entity.CreatedOn }); DBEntity.SaveChanges(); } } entity.Id = model.Id; response.CreateResponse(entity, DataResponseStatus.OK); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { ex.Log(); } finally { base.DBClose(); } return(response); }
public DataResponse <EntityBusinessMaster> UpdateBusiness(EntityBusinessMaster entity) { var response = new DataResponse <EntityBusinessMaster>(); try { base.DBInit(); var model = DBEntity.BusinessMasters.FirstOrDefault(a => a.Id == entity.Id); model.BusinessName = entity.BusinessName; model.Description = entity.Description; model.IsActive = entity.IsActive; model.UpdatedOn = entity.UpdatedOn; model.UpdatedBy = entity.UpdatedBy; if (base.DBSaveUpdate(model) > 0) { return(GetBusinessById(model.Id)); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { ex.Log(); } finally { base.DBClose(); } return(response); }
public DataResponse <EntityMarketing> Update(EntityMarketing entity) { var response = new DataResponse <EntityMarketing>(); try { base.DBInit(); var model = DBEntity.MarketingDocuments.FirstOrDefault(a => a.Id == entity.Id); model.Name = entity.Name; model.Description = entity.Description; model.DocumentTypeId = entity.DocumentTypeId; model.CategoryId = entity.CategoryId; model.UpdatedBy = entity.CurrentUserId; model.UpdatedOn = System.DateTime.UtcNow; if (DBEntity.SaveChanges() > 0) { return(GetMarketingById(model.Id, entity.CurrentUserId, entity.BusinessId)); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { ex.Log(); } finally { base.DBClose(); } return(response); }
public DataResponse <EntityColumnLookup> UpdateReportColumnLookup(EntityColumnLookup entity) { var response = new DataResponse <EntityColumnLookup>(); try { base.DBInit(); var model = DBEntity.LookupServiceColumns.FirstOrDefault(a => a.Id == entity.Id); model.Text = entity.Text; model.ColumnId = entity.ColumnId; model.UpdatedBy = entity.UpdatedBy; model.UpdatedOn = System.DateTime.UtcNow; if (base.DBSaveUpdate(model) > 0) { return(GetReportColumnLookupById(model.Id)); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { ex.Log(); } finally { base.DBClose(); } return(response); }
public DataResponse <EntityNotificationType> UpdateNoificationTypeById(EntityNotificationType entity) { var response = new DataResponse <EntityNotificationType>(); try { base.DBInit(); var model = DBEntity.LookupNotificationTypes.FirstOrDefault(a => a.Id == entity.Id); model.Title = entity.Title; model.NotificationKey = entity.NotificationKey; model.UpdatedOn = entity.UpdatedOn; model.UpdatedBy = entity.UpdatedBy; if (base.DBSaveUpdate(model) > 0) { return(GetNoificationTypeById(model.Id)); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { ex.Log(); } finally { base.DBClose(); } return(response); }
public DataResponse <EntityPracticeType> UpdatePracticeSpeciality(EntityPracticeType entity) { var response = new DataResponse <EntityPracticeType>(); try { base.DBInit(); var model = DBEntity.LookupPracticeTypes.FirstOrDefault(a => a.Id == entity.Id); model.PracticeType = entity.PracticeType; model.IsActive = entity.IsActive; model.UpdatedOn = entity.UpdatedOn; model.UpdatedBy = entity.UpdatedBy; if (base.DBSaveUpdate(model) > 0) { return(GetPracticeTypeById(model.Id)); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { ex.Log(); } finally { base.DBClose(); } return(response); }
public static DataResponse <T> GetCached <T>(this DataResponse <T> obj, string name) { var dataResponse = new DataResponse <T>(); var cachedModel = (T)HttpRuntime.Cache[name]; if (cachedModel == null) { dataResponse.CreateResponse <T>(default(T), DataResponseStatus.NotFound); } else { dataResponse.CreateResponse <T>(cachedModel, DataResponseStatus.OK); } return(dataResponse); }
public DataResponse <EntityMarketingCategories> Insert(EntityMarketingCategories entity) { var response = new DataResponse <EntityMarketingCategories>(); try { base.DBInit(); var model = new Database.LookupMarketingCategory { Category = entity.Category, BusinessId = entity.BusinessId, CreatedOn = entity.CreatedOn, CreatedBy = entity.CreatedBy }; if (base.DBSave(model) > 0) { return(GetMarketingCategoryById(model.Id)); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { ex.Log(); } finally { base.DBClose(); } return(response); }
public DataResponse <EntityUser> Update(EntityUser entity) { var response = new DataResponse <EntityUser>(); try { base.DBInit(); var model = DBEntity.Users.FirstOrDefault(a => a.Id == entity.Id); model.FirstName = entity.FirstName; model.MiddleName = entity.MiddleName; model.LastName = entity.LastName; model.PhoneNumber = entity.PhoneNumber; if (DBEntity.SaveChanges() < 0) { response.CreateResponse(DataResponseStatus.InternalServerError); } else { return(GetCurrentUserbyId(model.Id)); } } catch (Exception ex) { ex.Log(); } finally { base.DBClose(); } return(response); }
public DataResponse <EntityCountry> UpdateCountry(EntityCountry entity) { var response = new DataResponse <EntityCountry>(); try { base.DBInit(); var model = DBEntity.LookupCountries.FirstOrDefault(a => a.Id == entity.Id); model.CountryName = entity.CountryName; model.CountryCode = entity.CountryCode; model.IsActive = entity.IsActive; model.UpdatedOn = entity.UpdatedOn; model.UpdatedBy = entity.UpdatedBy; if (base.DBSaveUpdate(model) > 0) { return(GetCountryById(model.Id)); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { ex.Log(); } finally { base.DBClose(); } return(response); }
public DataResponse <EntityDocumentTypes> Update(EntityDocumentTypes entity) { var response = new DataResponse <EntityDocumentTypes>(); try { base.DBInit(); #region Prepare model var model = DBEntity.LookupDocumentTypes.FirstOrDefault(a => a.Id == entity.Id); model.DocumentType = entity.DocumentType; model.UpdatedBy = entity.UpdatedBy; model.UpdatedOn = entity.UpdatedOn; #endregion if (base.DBSaveUpdate(model) > 0) { return(GetDocumentTypeById(model.Id)); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { ex.Log(); } finally { base.DBClose(); } return(response); }
public DataResponse <EntityPrivilegeModules> UpdatePrivilegeModuleById(EntityPrivilegeModules entity) { var response = new DataResponse <EntityPrivilegeModules>(); try { base.DBInit(); var model = DBEntity.ModulesMasters.FirstOrDefault(a => a.Id == entity.Id); model.Title = entity.Title; model.Description = entity.Description; model.UpdatedOn = entity.UpdatedOn; model.UpdatedBy = entity.UpdatedBy; model.IsActive = entity.IsActive; if (base.DBSaveUpdate(model) > 0) { return(GetPrivilegeModulesById(model.Id)); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { ex.Log(); } finally { base.DBClose(); } return(response); }
public DataResponse <EntityReps> Insert(EntityReps entity) { var response = new DataResponse <EntityReps>(); try { base.DBInit(); var model = new Database.Rep { UserId = entity.UserId, RepGroupId = entity.RepGroupId, CreatedBy = entity.CreatedBy, CreatedOn = entity.CreatedOn, IsActive = true, }; if (base.DBSave(model) > 0) { if (entity.ServiceIds != null && entity.ServiceIds.Count() > 0) { foreach (var item in entity.ServiceIds) { DBEntity.RepServiceMappers.Add(new RepServiceMapper { ServiceId = item, RepId = model.Id, CreatedBy = entity.CreatedBy, CreatedOn = entity.CreatedOn }); DBEntity.SaveChanges(); } } entity.Id = model.Id; response.CreateResponse(entity, DataResponseStatus.OK); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { ex.Log(); } finally { base.DBClose(); } return(response); }
public DataResponse <EntityNote> GetNoteById(int ParentId, int ParentTypeId) { DataResponse <EntityNote> response = new DataResponse <EntityNote>(); try { base.DBInit(); base.DBInit(); var query = DBEntity.Notes.Where(a => a.ParentTypeId == ParentTypeId & a.ParentId == ParentId).OrderByDescending(a => a.Id).FirstOrDefault(); var entity = new EntityNote { Id = query.Id, ParentId = query.ParentId, ParentTypeId = query.ParentTypeId, Description = query.Description, CreatedBy = query.CreatedBy, CreatedOn = query.CreatedOn, UserDetails = new UserDetails { UserId = query.CreatedBy, Name = query.User.FirstName + " " + query.User.LastName, date = query.CreatedOn.ToString() } }; if (query != null) { response.CreateResponse(entity, DataResponseStatus.OK); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { response.ThrowError(ex); } finally { base.DBClose(); } return(response); }
public DataResponse <EntityDepartments> Update(EntityDepartments entity) { var response = new DataResponse <EntityDepartments>(); try { base.DBInit(); #region Prepare model var model = DBEntity.Departments.FirstOrDefault(a => a.Id == entity.Id); model.DepartmentName = entity.DepartmentName; model.Description = entity.Description; model.IsActive = entity.IsActive; model.UpdatedOn = entity.UpdatedOn; model.UpdatedBy = entity.UpdatedBy; #endregion if (base.DBSaveUpdate(model) > 0) { IEnumerable <DepartmentPrivilege> departmentPrivilege = DBEntity.DepartmentPrivileges.Where(a => a.DepartmentId == model.Id).ToList(); if (departmentPrivilege.Count() > 0) { DBEntity.DepartmentPrivileges.RemoveRange(departmentPrivilege); DBEntity.SaveChanges(); } if (entity.DepartmentPrivilegeIds != null && entity.DepartmentPrivilegeIds.Count() > 0) { foreach (var item in entity.DepartmentPrivilegeIds) { DBEntity.DepartmentPrivileges.Add(new DepartmentPrivilege { DepartmentId = model.Id, PrivilegeId = item, CreatedBy = model.CreatedBy, CreatedOn = model.CreatedOn, UpdatedBy = entity.UpdatedBy, UpdatedOn = entity.UpdatedOn }); DBEntity.SaveChanges(); } } return(GetDepartmentById(model.Id)); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { ex.Log(); } finally { base.DBClose(); } return(response); }
public DataResponse <EntityUsers> insertUserProfile(EntityProfile entity) { var response = new DataResponse <EntityUsers>(); try { base.DBInit(); var model = new Database.UserProfile { UserId = entity.UserId, WorkEmail = entity.WorkEmail, HomePhone = entity.HomePhone, AdditionalPhone = entity.AdditionalPhone, AddressLine1 = entity.AddressLine1, AddressLine2 = entity.AddressLine2, City = entity.City, Zip = entity.Zip, StateId = entity.StateId, CreatedBy = entity.CreatedBy, CreatedOn = entity.CreatedOn, UpdatedBy = entity.UpdatedBy, UpdatedOn = entity.UpdatedOn, Startdate = entity.Startdate }; if (base.DBSave(model) > 0) { if (entity.DepartmentIds != null && entity.DepartmentIds.Count() > 0) { foreach (var item in entity.DepartmentIds) { DBEntity.UserDepartments.Add(new UserDepartment { UserId = entity.UserId.Value, DepartmentId = item, CreatedBy = entity.CreatedBy, CreatedOn = entity.CreatedOn }); DBEntity.SaveChanges(); } } return(GetUserById(model.UserId.Value)); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { ex.Log(); } finally { base.DBClose(); } return(response); }
public DataResponse <EntityMarketing> Insert(EntityMarketing entity) { var response = new DataResponse <EntityMarketing>(); try { base.DBInit(); var model = new Database.MarketingDocument { Name = entity.Name, DocumentTypeId = entity.DocumentTypeId, Description = entity.Description, //Url=entity.Url, CategoryId = entity.CategoryId, CreatedOn = entity.CreatedOn, CreatedBy = entity.CreatedBy, BusinessId = entity.BusinessId, }; if (base.DBSave(model) > 0) { entity.Id = model.Id; response.CreateResponse <EntityMarketing>(entity, DataResponseStatus.OK); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { ex.Log(); } finally { base.DBClose(); } return(response); }
public DataResponse <EntityBusinessMaster> Insert(EntityBusinessMaster entity) { var response = new DataResponse <EntityBusinessMaster>(); try { base.DBInit(); var model = new Database.BusinessMaster { BusinessName = entity.BusinessName, RelativeUrl = entity.BusinessName.ToLower().Replace(" ", "-"), Description = entity.Description, CreatedBy = 1, CreatedOn = System.DateTime.UtcNow, IsActive = true, Status = 1 }; if (base.DBSave(model) > 0) { entity.Id = model.Id; response.CreateResponse <EntityBusinessMaster>(entity, DataResponseStatus.OK); return(response); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { ex.Log(); } finally { base.DBClose(); } return(response); }
public DataResponse <EntityReps> Update(EntityReps entity) { var response = new DataResponse <EntityReps>(); try { base.DBInit(); entity.UpdatedOn = DateTime.UtcNow; var model = DBEntity.Reps.FirstOrDefault(a => a.Id == entity.Id); model.UserId = entity.UserId; model.RepGroupId = entity.RepGroupId; model.IsActive = entity.IsActive; model.UpdatedOn = entity.UpdatedOn; model.UpdatedBy = entity.UpdatedBy; if (base.DBSaveUpdate(model) > 0) { IEnumerable <RepServiceMapper> RepManagerIds = DBEntity.RepServiceMappers.Where(a => a.RepId == model.Id).ToList(); if (RepManagerIds.Count() > 0) { DBEntity.RepServiceMappers.RemoveRange(RepManagerIds); DBEntity.SaveChanges(); } if (entity.ServiceIds != null && entity.ServiceIds.Count() > 0) { foreach (var item in entity.ServiceIds) { DBEntity.RepServiceMappers.Add(new RepServiceMapper { RepId = entity.Id, ServiceId = item, CreatedBy = model.CreatedBy, CreatedOn = model.CreatedOn }); DBEntity.SaveChanges(); } } return(GetRepById(model.Id)); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { ex.Log(); } finally { base.DBClose(); } return(response); }
public DataResponse <EntityCountry> Insert(EntityCountry entity) { var response = new DataResponse <EntityCountry>(); try { base.DBInit(); var model = new Database.LookupCountry { CountryName = entity.CountryName, CountryCode = entity.CountryCode, CreatedBy = entity.CreatedBy, CreatedOn = System.DateTime.UtcNow, IsActive = entity.IsActive }; if (base.DBSave(model) > 0) { entity.Id = model.Id; response.CreateResponse(entity, DataResponseStatus.OK); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { ex.Log(); response.ThrowError(ex); } finally { base.DBClose(); } return(response); }
public DataResponse <EntityPracticeAddress> Update(EntityPracticeAddress entity) { var response = new DataResponse <EntityPracticeAddress>(); try { base.DBInit(); if (DBEntity.Addresses.FirstOrDefault(a => a.Id != entity.Id && a.LocationId == entity.LocationId) != null) { response.Id = entity.Id; response.Status = DataResponseStatus.Found; response.Message = "LocationId already exists"; } else { var model = DBEntity.Addresses.FirstOrDefault(a => a.Id == entity.Id); model.LocationId = entity.LocationId; if (base.DBSaveUpdate(model) > 0) { entity.Id = model.Id; response.CreateResponse(entity, DataResponseStatus.OK); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } } catch (Exception ex) { ex.Log(); } finally { base.DBClose(); } return(response); }
public DataResponse <EntityNotification> GetNotificationById(int NotificationId) { DataResponse <EntityNotification> response = new DataResponse <EntityNotification>(); try { base.DBInit(); var query = base.DBEntity.Notifications.Where(a => a.Id == NotificationId).FirstOrDefault(); var entity = new EntityNotification { NotificationId = query.Id, Message = query.Message, TargetId = query.TargetId, TargetTypeId = query.TargetType, UserId = query.NotificationUsers.FirstOrDefault().UserId }; if (query != null) { response.CreateResponse(entity, DataResponseStatus.OK); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { //response.ThrowError(ex); ex.Log(); } finally { base.DBClose(); } return(response); }
public DataResponse <EntityPrivilege> Insert(EntityPrivilege entity) { var response = new DataResponse <EntityPrivilege>(); try { base.DBInit(); var model = new Database.Privilege { Title = entity.Title, Description = entity.Description, PrivilegeKey = entity.PrivilegeKey, ModuleId = entity.ModuleId, CreatedBy = entity.CreatedBy, CreatedOn = System.DateTime.UtcNow }; if (base.DBSave(model) > 0) { entity.Id = model.Id; response.CreateResponse(entity, DataResponseStatus.OK); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { ex.Log(); } finally { base.DBClose(); } return(response); }