public async Task <BasicResponse> CreatePortalLocation(PortalLocationCreateModel model) { using (var transaction = _dbConfigContext.Database.BeginTransaction()) { try { var userId = _workContext.UserGuid; var entity = new PortalLocationControls(); entity = _mapper.Map <PortalLocationControls>(model); entity.CreatedBy = userId; entity.CreatedDate = DateTime.Now; var result = await _dbConfigContext.PortalLocationControls.AddAsync(entity); await _dbConfigContext.SaveChangesAsync(); transaction.Commit(); transaction.Dispose(); return(BasicResponse.Succeed("Success")); } catch { transaction.Rollback(); transaction.Dispose(); throw; } } }
public BasicResponse UpdateYachtMerchantCharterFee(YachtMerchantCharterFeeUpdateModel model) { try { var entity = _dbYachtContext.YachtMerchantCharterFeeOptions.AsNoTracking().Where(x => x.Deleted == false && x.Id == model.Id).FirstOrDefault(); if (entity != null) { var userId = _workContext.UserGuid; entity = _mapper.Map <YachtMerchantCharterFeeUpdateModel, YachtMerchantCharterFeeOptions>(model, entity); entity.LastModifiedBy = userId; entity.LastModifiedDate = DateTime.Now; _dbYachtContext.YachtMerchantCharterFeeOptions.Update(entity); _dbYachtContext.SaveChanges(); return(BasicResponse.Succeed("Update successfully!")); } return(BasicResponse.Failed("Update fail")); } catch { throw; } }
public async Task <BasicResponse> UpdatePortalLocation(PortalLocationCreateModel model) { using (var transaction = _dbConfigContext.Database.BeginTransaction()) { try { var userId = _workContext.UserGuid; var entity = _dbConfigContext.PortalLocationControls.Where(x => x.Deleted == false && x.IsActive == true && x.Id == model.Id).FirstOrDefault(); if (entity == null) { transaction.Dispose(); return(BasicResponse.Failed("Fail")); } entity = _mapper.Map <PortalLocationCreateModel, PortalLocationControls>(model, entity); entity.LastModifiedBy = userId; entity.LastModifiedDate = DateTime.Now; var result = _dbConfigContext.PortalLocationControls.Update(entity); await _dbConfigContext.SaveChangesAsync(); transaction.Commit(); transaction.Dispose(); return(BasicResponse.Succeed("Success")); } catch { transaction.Rollback(); transaction.Dispose(); throw; } } }
public async Task <BasicResponse> DisablePortalLocation(int id) { using (var transaction = await _dbConfigContext.Database.BeginTransactionAsync()) { try { var entity = _dbConfigContext.PortalLocationControls.Where(x => x.Deleted == false && x.IsActive == true && x.Id == id).FirstOrDefault(); if (entity == null) { transaction.Dispose(); return(BasicResponse.Failed("Fail")); } entity.IsActive = false; entity.LastModifiedBy = GetCurrentUserId(); entity.LastModifiedDate = DateTime.Now; _dbConfigContext.PortalLocationControls.Update(entity); await _dbConfigContext.SaveChangesAsync(); transaction.Commit(); transaction.Dispose(); return(BasicResponse.Succeed("Success")); } catch { transaction.Rollback(); transaction.Dispose(); throw; } } }
public async Task<BasicResponse> CreateOrUpdateYachtAttribute(YachtAttributeCreateModel model) { try { var entity = _dbYachtContext.YachtAttributes.FirstOrDefault(x => x.Id == model.Id); if (entity != null) { entity = _mapper.Map<YachtAttributeCreateModel, YachtAttributes>(model, entity); entity.IsDefault = model.IsDefault; entity.LastModifiedBy = GetCurrentUserId(); entity.LastModifiedDate = DateTime.Now; _dbYachtContext.YachtAttributes.Update(entity); } else { var newEntity = new YachtAttributes(); newEntity = _mapper.Map<YachtAttributeCreateModel, YachtAttributes>(model, newEntity); newEntity.UniqueId = UniqueIDHelper.GenerateRandomString(12, false); newEntity.IsDefault = model.IsDefault; newEntity.CreatedBy = GetCurrentUserId(); newEntity.CreatedDate = DateTime.Now; newEntity.LastModifiedBy = GetCurrentUserId(); newEntity.LastModifiedDate = DateTime.Now; _dbYachtContext.YachtAttributes.Add(newEntity); } await _dbYachtContext.SaveChangesAsync(); return BasicResponse.Succeed("Success"); } catch { throw; } }
public async Task <BasicResponse> DeleteMembershipPrivileges(int id) { using (var transaction = _dbConfigContext.Database.BeginTransaction()) { try { var entity = _dbConfigContext.AqmembershipDiscountPrivileges.FirstOrDefault(x => x.Id == id); if (entity != null) { entity.Deleted = true; } var result = _dbConfigContext.AqmembershipDiscountPrivileges.Update(entity); await _dbConfigContext.SaveChangesAsync(); transaction.Commit(); transaction.Dispose(); return(BasicResponse.Succeed("Success")); } catch { transaction.Rollback(); transaction.Dispose(); throw; } } }
public BasicResponse RemoveFile(int id) { using (var tran = _dataContext.Database.BeginTransaction()) { try { var fileInfo = _dataContext.FileStreamInfo.Where(x => x.FileId == id).FirstOrDefault(); if (fileInfo != null) { var fileData = _dataContext.FileStreamData.Where(x => x.FileId == fileInfo.FileId).FirstOrDefault(); var deleteFileInfo = _dataContext.FileStreamInfo.Remove(fileInfo); var deleteFileData = _dataContext.FileStreamData.Remove(fileData); _dataContext.SaveChanges(); tran.Commit(); tran.Dispose(); return(BasicResponse.Succeed("Remove file successfully")); } tran.Dispose(); return(BasicResponse.Failed("Remove file fail")); } catch { tran.Rollback(); tran.Dispose(); throw; } } }
public BasicResponse CreateYachtMerchantFileStream(YachtMerchantFileStreamCreateModel model) { try { var userId = _workContext.UserGuid; var entity = new YachtMerchantFileStreams(); entity = _mapper.Map <YachtMerchantFileStreams>(model); entity.Deleted = false; entity.LastModifiedBy = userId; entity.LastModifiedDate = DateTime.Now; _dbYachtContext.YachtMerchantFileStreams.Add(entity); _dbYachtContext.SaveChanges(); return(BasicResponse.Succeed("Create successfully!")); } catch { throw; } }
public BasicResponse DeleteYachtMerchantFileStream(int id) { try { var userId = _workContext.UserGuid; var entity = _dbYachtContext.YachtMerchantFileStreams.AsNoTracking().Where(x => x.Id == id && x.Deleted == false).FirstOrDefault(); entity.Deleted = true; entity.LastModifiedBy = userId; entity.LastModifiedDate = DateTime.Now; _dbYachtContext.YachtMerchantFileStreams.Update(entity); _dbYachtContext.SaveChanges(); return(BasicResponse.Succeed("Delete successfully!")); } catch { throw; } }
public async Task<BasicResponse> DeleteYachtAttribute(int id) { try { var entity = _dbYachtContext.YachtAttributes.FirstOrDefault(x => x.Id == id); if (entity != null) { entity.Deleted = true; _dbYachtContext.YachtAttributes.Update(entity); await _dbYachtContext.SaveChangesAsync(); return BasicResponse.Succeed("Success"); } else return BasicResponse.Failed("Not Found This Yacht Attribute"); } catch { throw; } }
public async Task <BasicResponse> CreateOrUpdateMembershipPrivileges(MembershipPrivilegesCreateModel model) { try { var check = CheckValidMembershipPrivileges(model); if (check) { var entity = _dbConfigContext.AqmembershipDiscountPrivileges.FirstOrDefault(x => x.Id == model.ID); if (entity != null) { entity.Name = model.Name; entity.Remark = model.Remark; entity.EffectiveDate = model.EffectiveDate; entity.EffectiveEndDate = model.EffectiveEndDate; entity.LastModifiedBy = GetCurrentUserId(); entity.LastModifiedDate = DateTime.Now; entity.RoleFid = model.RoleFID; var details = _dbConfigContext.AqmembershipDiscountPrivilegeDetails.Where(x => x.PrivilegeFid == model.ID).ToList(); foreach (var i in details) { i.LastModifiedBy = GetCurrentUserId(); i.LastModifiedDate = DateTime.Now; i.DiscountPercent = model.DataDetail.Find(x => x.ID == i.Id).DiscountPercent.GetValueOrDefault(); } _dbConfigContext.AqmembershipDiscountPrivileges.Update(entity); _dbConfigContext.AqmembershipDiscountPrivilegeDetails.UpdateRange(details); UpdateOldMembershipPrivileges(entity); _dbConfigContext.AqmembershipDiscountPrivileges.UpdateRange(entity); } else { var newMF = _mapper.Map <MembershipPrivilegesCreateModel, AqmembershipDiscountPrivileges>(model); newMF.CreatedBy = GetCurrentUserId(); newMF.CreatedDate = DateTime.Now; newMF.LastModifiedBy = GetCurrentUserId(); newMF.LastModifiedDate = DateTime.Now; _dbConfigContext.AqmembershipDiscountPrivileges.Add(newMF); await _dbConfigContext.SaveChangesAsync(); var newDetails = _mapper.Map <List <MembershipPrivilegesDetailCreateModel>, List <AqmembershipDiscountPrivilegeDetails> >(model.DataDetail); foreach (var i in newDetails) { i.PrivilegeFid = newMF.Id; i.LastModifiedBy = GetCurrentUserId(); i.LastModifiedDate = DateTime.Now; } _dbConfigContext.AqmembershipDiscountPrivilegeDetails.AddRange(newDetails); UpdateOldMembershipPrivileges(newMF); } await _dbConfigContext.SaveChangesAsync(); return(BasicResponse.Succeed("Success")); } else { return(BasicResponse.Failed("Effective Date Invalid!")); } } catch { throw; } }