public Operation Delete(SlsProductReceive obj)
        {
            Operation objOperation = new Operation { Success = true, OperationId = obj.Id };
            _SlsProductReceiveRepository.Delete(obj);

            try
            {
                _UnitOfWork.Commit();
            }
            catch (Exception)
            {

                objOperation.Success = false;
            }
            return objOperation;
        }
        public ActionResult SaveReceivedByDistributor(SlsProductReceive ProductRecievedobj, List<SlsProductReceiveDetail> ProductRecievedDetailList)
        {
            int userId = Convert.ToInt32(Session["userId"]);
            int companyId = Convert.ToInt32(Session["companyId"]);
            Operation objOperation = new Operation { Success = false };

            if (ModelState.IsValid && ProductRecievedDetailList != null)
            {
                if (ProductRecievedobj.Id == 0)
                {
                    if ((bool)Session["Add"])
                    {
                        ProductRecievedobj.CreatedBy = userId;
                        ProductRecievedobj.CreatedDate = DateTime.Now;
                        objOperation = _SlsProductReceiveService.Save(ProductRecievedobj);

                        int ProductReceiveId = Convert.ToInt32(objOperation.OperationId);

                        foreach (var item in ProductRecievedDetailList)
                        {

                            SlsProductReceiveDetail objSLsProductReceiveDetail = _SlsProductReceiveService.GetDetailById(item.Id);

                            if (objSLsProductReceiveDetail != null)
                            {
                                objSLsProductReceiveDetail.SlsProductReceiveId = ProductRecievedobj.Id;
                                objSLsProductReceiveDetail.SlsProductId = item.SlsProductId;
                                objSLsProductReceiveDetail.ReceivedQuantity = item.ReceivedQuantity;
                                objSLsProductReceiveDetail.DeliveryQuantity = item.DeliveryQuantity;
                                objSLsProductReceiveDetail.SlsUnitId = item.SlsUnitId;
                                objSLsProductReceiveDetail.Remarks = item.Remarks;
                                _SlsProductReceiveService.UpdateDetail(objSLsProductReceiveDetail);
                            }
                            else
                            {
                                objSLsProductReceiveDetail = new SlsProductReceiveDetail();
                                objSLsProductReceiveDetail.SlsProductReceiveId = ProductReceiveId;
                                objSLsProductReceiveDetail.SlsProductId = item.SlsProductId;
                                objSLsProductReceiveDetail.ReceivedQuantity = item.ReceivedQuantity;
                                objSLsProductReceiveDetail.DeliveryQuantity = item.DeliveryQuantity;
                                objSLsProductReceiveDetail.SlsUnitId = item.SlsUnitId;
                                objSLsProductReceiveDetail.Remarks = item.Remarks;
                                _SlsProductReceiveService.SaveDetail(objSLsProductReceiveDetail);
                            }

                        }

                    }

                }
                else
                {
                    if ((bool)Session["Edit"])
                    {
                        ProductRecievedobj.ModifiedBy = userId;
                        ProductRecievedobj.ModifiedDate = DateTime.Now;
                        objOperation = _SlsProductReceiveService.Update(ProductRecievedobj);

                        foreach (var item in ProductRecievedDetailList)
                        {
                            SlsProductReceiveDetail objSlsProductReceiveDetail = _SlsProductReceiveService.GetDetailById(item.Id);
                            if (objSlsProductReceiveDetail != null)
                            {
                                objSlsProductReceiveDetail.SlsProductReceiveId = ProductRecievedobj.Id;
                                objSlsProductReceiveDetail.SlsProductId = item.SlsProductId;
                                objSlsProductReceiveDetail.ReceivedQuantity = item.ReceivedQuantity;
                                objSlsProductReceiveDetail.DeliveryQuantity = item.DeliveryQuantity;
                                objSlsProductReceiveDetail.SlsUnitId = item.SlsUnitId;
                                objSlsProductReceiveDetail.Remarks = item.Remarks;
                                _SlsProductReceiveService.UpdateDetail(objSlsProductReceiveDetail);
                            }
                            else
                            {
                                objSlsProductReceiveDetail = new SlsProductReceiveDetail();
                                objSlsProductReceiveDetail.SlsProductReceiveId = ProductRecievedobj.Id;
                                objSlsProductReceiveDetail.SlsProductId = item.SlsProductId;
                                objSlsProductReceiveDetail.ReceivedQuantity = item.ReceivedQuantity;
                                objSlsProductReceiveDetail.DeliveryQuantity = item.DeliveryQuantity;
                                objSlsProductReceiveDetail.SlsUnitId = item.SlsUnitId;
                                objSlsProductReceiveDetail.Remarks = item.Remarks;
                                _SlsProductReceiveService.SaveDetail(objSlsProductReceiveDetail);
                            }

                        }

                    }
                }
                objOperation = _ProductReceiveService.Commit();

            }

            return Json(objOperation, JsonRequestBehavior.DenyGet);
        }
        public Operation Save(SlsProductReceive obj)
        {
            Operation objOperation = new Operation { Success = true };

            long Id = _SlsProductReceiveRepository.AddEntity(obj);
            objOperation.OperationId = Id;

            try
            {
                _UnitOfWork.Commit();
            }
            catch (Exception ex)
            {
                objOperation.Success = false;
            }
            return objOperation;
        }