public static SlsSalesReturnDetail MapToSlsSalesReturnDetail(SlsSalesReturnDetailViewModel obj)
        {
            SlsSalesReturnDetail model = new SlsSalesReturnDetail();

            model.Id = obj.Id;

            model.SlsReturnId = obj.SlsReturnId;
            model.SlsProductId = obj.SlsProductId;
            model.ReturnedQuantity = obj.ReturnedQuantity;
            model.Rate = obj.Rate;
            model.SlsUnitId = obj.SlsUnitId;

            return model;
        }
        public void ManageStockForSalesReturn(int storedId, int salesReturnId, DateTime date,
            SlsSalesReturnDetail returnObj, string operation)
        {
            //Execute it inside Transaction Scope...
            InvStockInOut obj = new InvStockInOut();
            obj.InvStoreId = storedId;
            //1=Receive,2=Issue,3-damage,4-transfer,5-return
            obj.TransactionType = 5;
            obj.RefId = salesReturnId;
            obj.SlsProductId = returnObj.SlsProductId;
            obj.Quantity = returnObj.ReturnedQuantity;
            obj.SlsUnitId = returnObj.SlsUnitId;
            //0=Out, 1=In
            obj.Status = 1;
            obj.TransactionDate = date;

            switch (operation)
            {
                case "Add":
                    //_stockInService.SaveInternal(obj);
                    _StockInRepository.AddEntity(obj);
                    break;

                case "Update":
                    {
                        var allStockIns = _StockInRepository.GetAll();
                        //1=Receive,2=Issue,3-damage,4-transfer,5-return
                        try
                        {
                            allStockIns = allStockIns.Where(i => i.TransactionType == 5 && i.RefId == salesReturnId &&
                                i.InvStoreId == storedId && i.TransactionDate == date && i.SlsProductId == returnObj.SlsProductId
                                && i.SlsUnitId == returnObj.SlsUnitId).ToList();
                            if (allStockIns != null && allStockIns.Count() > 0)
                            {
                                obj = allStockIns.First();
                                obj.Quantity = returnObj.ReturnedQuantity;
                                _StockInRepository.Update(obj);
                            }
                            else
                            {
                                //add
                                _StockInRepository.AddEntity(obj);
                            }
                        }
                        catch (Exception ex)
                        {

                        }
                    }
                    break;

                case "Delete":
                    {
                        var allStockIns = _StockInRepository.GetAll();
                        //1=Receive,2=Issue,3-damage,4-transfer,5-return
                        try
                        {
                            allStockIns = allStockIns.Where(i => i.TransactionType == 5 && i.RefId == salesReturnId &&
                                i.InvStoreId == storedId && i.TransactionDate == date && i.SlsProductId == returnObj.SlsProductId
                                && i.SlsUnitId == returnObj.SlsUnitId).ToList();
                            if (allStockIns != null && allStockIns.Count() > 0)
                            {
                                obj = allStockIns.First();
                                _StockInRepository.Delete(obj);
                            }
                        }
                        catch (Exception ex)
                        {

                        }
                    }
                    break;

                default:
                    break;
            }
            _StockInRepository.SaveChanges();
        }