public BaseResponse <bool> CreateProductPricing(ProductPricingCreateOrUpdateModel model)
        {
            try
            {
                var products = _context.YachtMerchantProductPricings.Where(x => x.ProductFid == model.ProductFid && !x.Deleted && x.EffectiveEndDate > DateTime.Now.Date).ToList();

                if (products.Count > 0)
                {
                    var supplierLast  = products[products.Count - 1];
                    var isExistedInfo = false;
                    isExistedInfo = CheckdDateTimeInsert(model.EffectiveDate, model.EffectiveEndDate, supplierLast.EffectiveDate, supplierLast.EffectiveEndDate);

                    if (!isExistedInfo)
                    {
                        return(BaseResponse <bool> .NotFound(false));
                    }
                }
                if (model.EffectiveEndDate.HasValue)
                {
                    if (model.EffectiveDate.Date >= model.EffectiveEndDate.Value.Date)
                    {
                        return(BaseResponse <bool> .BadRequest(false));
                    }
                }

                var entity = new YachtMerchantProductPricings();
                entity.ProductFid       = model.ProductFid;
                entity.EffectiveDate    = model.EffectiveDate;
                entity.EffectiveEndDate = model.EffectiveEndDate;
                entity.Price            = model.Price;
                entity.CultureCode      = model.CultureCode;
                entity.CurrencyCode     = model.CurrencyCode;
                entity.Deleted          = false;
                entity.CreatedBy        = GetUserGuidId();
                entity.CreatedDate      = DateTime.Now;
                entity.LastModifiedDate = DateTime.Now;
                entity.LastModifiedBy   = GetUserGuidId();
                _context.YachtMerchantProductPricings.Add(entity);
                _context.SaveChangesAsync().Wait();
                return(BaseResponse <bool> .Success(true));
            }
            catch (Exception ex)
            {
                return(BaseResponse <bool> .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace));
            }
        }
示例#2
0
 public BaseResponse <bool> Create(ProductPricingCreateModel model)
 {
     try
     {
         var entity = new YachtMerchantProductPricings();
         entity.InjectFrom(model);
         entity.Deleted          = false;
         entity.CreatedBy        = GetUserGuidId();
         entity.CreatedDate      = DateTime.Now;
         entity.LastModifiedDate = DateTime.Now;
         entity.LastModifiedBy   = GetUserGuidId();
         _context.YachtMerchantProductPricings.Add(entity);
         _context.SaveChangesAsync().Wait();
         return(BaseResponse <bool> .Success(true));
     }
     catch (Exception ex)
     {
         return(BaseResponse <bool> .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace));
     }
 }
        public BaseResponse <bool> CreateYachtMerchantProductInventory(YachtMerchantProductInventoryCreateModel model)
        {
            using (var tran = _context.Database.BeginTransaction())
            {
                try
                {
                    var date   = DateTime.Now;
                    var entity = new YachtMerchantProductInventories();
                    entity.InjectFrom(model);

                    //Create Product
                    entity.UniqueId         = UniqueIDHelper.GenarateRandomString(12);
                    entity.IsActiveForSales = true;
                    entity.IsStockControl   = true;
                    entity.Deleted          = false;
                    entity.CreatedBy        = GetUserGuidId();
                    entity.CreatedDate      = date;
                    entity.LastModifiedBy   = GetUserGuidId();
                    entity.LastModifiedDate = date;
                    _context.YachtMerchantProductInventories.Add(entity);
                    _context.SaveChangesAsync().Wait();

                    //Create Product Price of Product
                    if (model.Price > 0)
                    {
                        var entityProductPricing = new YachtMerchantProductPricings();
                        entityProductPricing.InjectFrom(model);
                        entityProductPricing.ProductFid       = entity.Id;
                        entityProductPricing.Deleted          = false;
                        entityProductPricing.CreatedBy        = GetUserGuidId();
                        entityProductPricing.CreatedDate      = date;
                        entityProductPricing.LastModifiedBy   = GetUserGuidId();
                        entityProductPricing.LastModifiedDate = date;
                        _context.YachtMerchantProductPricings.Add(entityProductPricing);
                    }


                    //Create Product Supplier of Product
                    if (model.VendorFid > 0)
                    {
                        var entityProductSupplier = new YachtMerchantProductSuppliers();
                        entityProductSupplier.ProductFid       = entity.Id;
                        entityProductSupplier.VendorFid        = model.VendorFid;
                        entityProductSupplier.EffectiveDate    = model.EffectiveDateSupplier;
                        entityProductSupplier.EffectiveEndDate = model.EffectiveEndDateSupplier;
                        entityProductSupplier.Remark           = model.Remark;
                        entityProductSupplier.Deleted          = false;
                        entityProductSupplier.CreatedBy        = GetUserGuidId();
                        entityProductSupplier.CreatedDate      = date;
                        entityProductSupplier.LastModifiedBy   = GetUserGuidId();
                        entityProductSupplier.LastModifiedDate = date;
                        _context.YachtMerchantProductSuppliers.Add(entityProductSupplier);
                    }

                    //Save and Commit Transaction
                    _context.SaveChangesAsync().Wait();
                    tran.Commit();
                    return(BaseResponse <bool> .Success(true));
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    return(BaseResponse <bool> .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace));
                }
            }
        }