public BaseResponse <bool> CreateProductSupplier(YachtMerchantProductSupplierViewModel model) { try { if (model.EffectiveEndDate.HasValue && model.EffectiveEndDate.Value.Date < model.EffectiveDate.Date) { return(BaseResponse <bool> .BadRequest(false)); } var entity = new YachtMerchantProductSuppliers(); entity.ProductFid = model.ProductFid; entity.VendorFid = model.VendorFid; entity.EffectiveDate = model.EffectiveDate; entity.EffectiveEndDate = model.EffectiveEndDate; entity.Remark = model.Remark; entity.Deleted = false; entity.CreatedBy = GetUserGuidId(); entity.CreatedDate = DateTime.Now; entity.LastModifiedDate = DateTime.Now; entity.LastModifiedBy = GetUserGuidId(); _context.YachtMerchantProductSuppliers.Add(entity); _context.SaveChangesAsync().Wait(); return(BaseResponse <bool> .Success(true)); } catch (Exception ex) { return(BaseResponse <bool> .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace)); } }
public IActionResult CreateProductSupplier(YachtMerchantProductSupplierViewModel model) { var result = _yachtMerchantProductVendorServices.CreateProductSupplier(model); if (result.IsSuccessStatusCode) { return(Ok(result)); } return(BadRequest()); }
public IActionResult UpdateProductSupplier(YachtMerchantProductSupplierViewModel model) { if (model == null) { return(BadRequest()); } var result = _yachtMerchantProductInventoryService.UpdateProductSupplier(model); if (result.IsSuccessStatusCode) { return(Ok(result)); } return(BadRequest()); }
public BaseResponse <bool> UpdateProductSupplier(YachtMerchantProductSupplierViewModel model) { try { var entity = _context.YachtMerchantProductSuppliers.FirstOrDefault(x => x.ProductFid == model.ProductFid && x.EffectiveDate > DateTime.Now.Date); if (entity == null) { return(BaseResponse <bool> .NotFound(false)); } var isExistedInfo = false; if (entity.EffectiveDate != null) { if (entity.EffectiveEndDate != null) { isExistedInfo = _context .YachtMerchantProductSuppliers .Any(r => r.Deleted == false && r.ProductFid == entity.ProductFid && r.EffectiveEndDate.GetValueOrDefault().Date > model.EffectiveEndDate.GetValueOrDefault().Date); } else { isExistedInfo = _context.YachtMerchantProductSuppliers .Any(r => r.Deleted == false && r.ProductFid == entity.ProductFid && r.EffectiveDate.AddDays(1).Date > model.EffectiveEndDate.GetValueOrDefault().Date); } } if (isExistedInfo) { return(BaseResponse <bool> .NotFound(false)); } entity.Remark = model.Remark; entity.EffectiveEndDate = model.EffectiveEndDate; _context.YachtMerchantProductSuppliers.Update(entity); _context.SaveChanges(); return(BaseResponse <bool> .Success(true)); } catch (Exception ex) { return(BaseResponse <bool> .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace)); } }