Пример #1
0
        public async Task <ResponseViewModel <QuantityViewModel> > CreateAndUpdate(QuantityViewModel QauntityObj)
        {
            ResponseViewModel <QuantityViewModel> ResObj = new ResponseViewModel <QuantityViewModel>();

            try
            {
                if (QauntityObj != null)
                {
                    bool IsNew = false;
                    InventoryDBContext dbContext = new InventoryDBContext(await connMethod.GetConnectionString(QauntityObj.ConnectionString));
                    /*Check if already exists*/
                    Brand_Quantity_Time_Received QuantityDBObj = dbContext.Brand_Quantity_Time_Received.Where(x => x.Inventory_Id == QauntityObj.Brand_Id).FirstOrDefault();
                    if (QuantityDBObj == null)
                    {
                        QuantityDBObj = new Brand_Quantity_Time_Received();
                        IsNew         = true;
                    }
                    QuantityDBObj.Brand_Id      = QauntityObj.Brand_Id;
                    QuantityDBObj.Quantity      = QauntityObj.Quantity;
                    QuantityDBObj.Time_Received = QauntityObj.Time_Received;
                    if (IsNew)
                    {
                        await dbContext.Brand_Quantity_Time_Received.AddAsync(QuantityDBObj);
                    }
                    await dbContext.SaveChangesAsync();

                    QauntityObj.Inventory_Id = QuantityDBObj.Inventory_Id;
                    ResObj.IsSuccess         = true;
                    List <QuantityViewModel> QuantityList = new List <QuantityViewModel>();
                    QuantityList.Add(QauntityObj);
                    ResObj.Data = QuantityList;
                }
                else
                {
                    ResObj.IsSuccess    = false;
                    ResObj.ErrorCode    = 400;
                    ResObj.ErrorDetails = "Parameter not provided.";
                }
            }
            catch (Exception ex)
            {
                ResObj.IsSuccess    = false;
                ResObj.ErrorCode    = 500;
                ResObj.ErrorDetails = ex.ToString();
            }
            return(ResObj);
        }
Пример #2
0
        public async Task <ResponseViewModel <QuantityViewModel> > Delete(QuantityViewModel QuantityObj)
        {
            ResponseViewModel <QuantityViewModel> ResObj = new ResponseViewModel <QuantityViewModel>();

            try
            {
                if (QuantityObj != null)
                {
                    InventoryDBContext dbContext = new InventoryDBContext(await connMethod.GetConnectionString(QuantityObj.ConnectionString));
                    /*Check if already exists*/
                    Brand_Quantity_Time_Received QuantityDBObj = dbContext.Brand_Quantity_Time_Received.Where(x => x.Inventory_Id == QuantityObj.Inventory_Id).FirstOrDefault();
                    if (QuantityDBObj != null)
                    {
                        dbContext.Brand_Quantity_Time_Received.Remove(QuantityDBObj);
                        await dbContext.SaveChangesAsync();

                        ResObj.IsSuccess = true;
                    }
                    else
                    {
                        ResObj.IsSuccess    = false;
                        ResObj.ErrorCode    = 404;
                        ResObj.ErrorDetails = "Record not found.";
                    }
                }
                else
                {
                    ResObj.IsSuccess    = false;
                    ResObj.ErrorCode    = 400;
                    ResObj.ErrorDetails = "Parameter not provided.";
                }
            }
            catch (Exception ex)
            {
                ResObj.IsSuccess    = false;
                ResObj.ErrorCode    = 500;
                ResObj.ErrorDetails = ex.ToString();
            }
            return(ResObj);
        }