public async Task <BasicResponse> CreateOrUpdateYachtTourAttribute(YachtTourAttributeCreateModel model) { try { var entity = _dbYachtContext.YachtTourAttributes.FirstOrDefault(x => x.Id == model.Id); if (entity != null) { entity = _mapper.Map <YachtTourAttributeCreateModel, YachtTourAttributes>(model, entity); entity.IsDefault = model.IsDefault; entity.LastModifiedBy = GetCurrentUserId(); entity.LastModifiedDate = DateTime.Now; _dbYachtContext.YachtTourAttributes.Update(entity); } else { var newEntity = new YachtTourAttributes(); newEntity = _mapper.Map <YachtTourAttributeCreateModel, YachtTourAttributes>(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.YachtTourAttributes.Add(newEntity); } await _dbYachtContext.SaveChangesAsync(); return(BasicResponse.Succeed("Success")); } catch { throw; } }
private YachtTourAttributes GenerateForUpdate(YachtTourAttributes entity) { var now = DateTime.Now.Date; var userId = UserContextHelper.UserId; entity.LastModifiedBy = userId; entity.LastModifiedDate = now; return(entity); }
private YachtTourAttributes GenerateForCreate(YachtTourAttributeCreateModel model) { var entity = new YachtTourAttributes(); entity.InjectFrom(model); entity.UniqueId = UniqueIDHelper.GenarateRandomString(12); var now = DateTime.Now.Date; var userId = UserContextHelper.UserId; entity.LastModifiedBy = userId; entity.CreatedBy = userId; entity.LastModifiedDate = now; entity.CreatedDate = now; return(entity); }