예제 #1
0
 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;
     }
 }
예제 #2
0
        public async Task <BaseResponse <bool> > CreateAsync(YachtAttributeCreateModel modelCreate)
        {
            try
            {
                var createItem = new YachtAttributes();
                createItem.InjectFrom(modelCreate);
                createItem.Deleted          = false;
                createItem.UniqueId         = UniqueIDHelper.GenarateRandomString(12);
                createItem.CreatedBy        = GetUserGuidId();
                createItem.CreatedDate      = DateTime.Now;
                createItem.LastModifiedBy   = GetUserGuidId();
                createItem.LastModifiedDate = DateTime.Now;
                await _context.YachtAttributes.AddAsync(createItem);

                await _context.SaveChangesAsync();

                return(BaseResponse <bool> .Success(true));
            }
            catch (Exception ex)
            {
                return(BaseResponse <bool> .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace));
            }
        }