public ActionResult Create()
        {
            PurcheaseReturns vm = new PurcheaseReturns();
            List <PurcheaseReturnDetails> PurcheaseReturnDetails = new List <PurcheaseReturnDetails>();

            vm.PurcheaseReturnDetails = PurcheaseReturnDetails;

            return(View(vm));
        }
/// <summary>
/// Update PurcheaseReturns
/// </summary>
/// <param name="entity"></param>
/// <returns>Message</returns>
        public async Task <string> UpdatePurcheaseReturns(PurcheaseReturns entity)
        {
            try
            {
                var result = await new PurcheaseReturnsRepository(logger).Update(entity);
                return(result);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                throw ex;
            }
        }
        public async Task <ActionResult> Edit(PurcheaseReturns data)
        {
            string result = string.Empty;

            try
            {
                result = await repo.UpdatePurcheaseReturns(data);
            }
            catch (Exception ex)
            {
                throw;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public async Task <JsonResult> Delete(string ids)
        {
            string result = string.Empty;

            string[]         IdList = ids.Split('~');
            PurcheaseReturns vm     = new PurcheaseReturns();

            try
            {
                result = await repo.IsDeletePurcheaseReturns(IdList, vm);
            }
            catch (Exception ex)
            {
                throw;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemple #5
0
        /// <summary>
        /// Insert PurcheaseReturns
        /// </summary>
        /// <param name="entity"></param>
        /// <returns>Message</returns>
        public async Task <string> InsertPurcheaseReturns(PurcheaseReturns entity)
        {
            var              result           = string.Empty;
            StockVM          stockdata        = new StockVM();
            StocksRepository stocksRepository = new StocksRepository(logger);

            try
            {
                using (TransactionScope txScope = new TransactionScope())
                {
                    var pud   = new PurcheaseReturnsRepository(logger).GetAll();
                    var pudid = 1;
                    if (pud != null)
                    {
                        pudid = pud.Id + 1;
                    }
                    entity.Id = pudid;
                    result    = await new PurcheaseReturnsRepository(logger).Insert(entity);
                    foreach (var data in entity.PurcheaseReturnDetails)
                    {
                        data.PurchaseReturnId = pudid;
                        result = await new PurcheaseReturnDetailsRepository(logger).Insert(data);

                        stockdata = new StocksRepository(logger).GetAll().Result.FirstOrDefault(c => c.ProductId == data.ProductId);
                        if (stockdata != null)
                        {
                            stockdata.Quantity = decimal.Subtract(stockdata.Quantity, data.Quantity);
                            result             = await new StocksRepository(logger).Update(stockdata);
                        }
                    }
                    txScope.Complete();
                    txScope.Dispose();
                }
                return(result);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                result = "Fail~" + ex.Message.ToString();
                throw ex;
            }
            finally
            {
            }
        }
/// <summary>
/// Delete PurcheaseReturns
/// </summary>
/// <param name="Id"></param>
/// <returns>Message</returns>
        public async Task <string> IsDeletePurcheaseReturns(string[] IdList, PurcheaseReturns entity)
        {
            string result = string.Empty;

            try
            {
                for (int i = 0; i < IdList.Length - 1; i++)
                {
                    result = await new PurcheaseReturnsRepository(logger).IsDelete(Convert.ToInt32(IdList[i]), entity);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                throw ex;
            }
            return(result);
        }