public Operation Save(InvProductReceiveDetail objProductReceiveDetail)
        {
            Operation objOperation = new Operation { Success = true };

               long Id = _ProductReceiveDetailRepository.AddEntity(objProductReceiveDetail);
               objOperation.OperationId = Id;

               try
               {
               _UnitOfWork.Commit();
               }
               catch (Exception ex)
               {
               objOperation.Success = false;
               }
               return objOperation;
        }
        public ActionResult Save(InvProductReceive ProductRecievedobj, List<InvProductReceiveDetail> ProductRecievedDetailList)
        {
            int userId = Convert.ToInt32(Session["userId"]);
            int companyId = Convert.ToInt32(Session["companyId"]);
            var dbfactory = new DatabaseFactory();

            IOfficeService offservice = new OfficeService(new OfficeRepository(dbfactory), new UnitOfWork(dbfactory));
            SlsOffice off = offservice.GetUserOffice(userId);

            int officeId = off.Id;
            IStoreService storeservice = new StoreService(new InvStoreRepository(dbfactory), new UnitOfWork(dbfactory));
            InvStore store = storeservice.GetStoresForOffice(officeId);

            int storeId = store.Id;
            Operation objOperation = new Operation { Success = false };

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

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

                        foreach (var item in ProductRecievedDetailList)
                        {

                            InvProductReceiveDetail objInvProductReceiveDetail = _ProductReceiveDetailService.GetById(item.Id);

                            if (objInvProductReceiveDetail != null)
                            {
                                objInvProductReceiveDetail.InvProductReceiveId = ProductRecievedobj.Id;
                                objInvProductReceiveDetail.SlsProductId = item.SlsProductId;
                                objInvProductReceiveDetail.ReceivedQuantity = item.ReceivedQuantity;
                                objInvProductReceiveDetail.IssuedQuantity = item.IssuedQuantity;
                                objInvProductReceiveDetail.SlsUnitId = item.SlsUnitId;
                                objInvProductReceiveDetail.Remarks = item.Remarks;
                                _ProductReceiveDetailService.Update(objInvProductReceiveDetail);
                            }
                            else
                            {
                                objInvProductReceiveDetail = new InvProductReceiveDetail();
                                objInvProductReceiveDetail.InvProductReceiveId = ProductReceiveId;
                                objInvProductReceiveDetail.SlsProductId = item.SlsProductId;
                                objInvProductReceiveDetail.ReceivedQuantity = item.ReceivedQuantity;
                                objInvProductReceiveDetail.IssuedQuantity = item.IssuedQuantity;
                                objInvProductReceiveDetail.SlsUnitId = item.SlsUnitId;
                                objInvProductReceiveDetail.Remarks = item.Remarks;
                                _ProductReceiveDetailService.Save(objInvProductReceiveDetail);

                                //InvStockInOut objStockOut = new InvStockInOut();
                                //objStockOut.TransactionType = 1;
                                //objStockOut.RefId = ProductReceiveId;
                                //objStockOut.Status = 0;
                                //objStockOut.SlsProductId = item.SlsProductId.Value;
                                //objStockOut.Quantity = item.ReceivedQuantity.Value;
                                //objStockOut.SlsUnitId = item.SlsUnitId.Value;

                            }

                        }

                    }

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

                        foreach (var item in ProductRecievedDetailList)
                        {
                            InvProductReceiveDetail objInvProductReceiveDetail = _ProductReceiveDetailService.GetById(item.Id);
                            if (objInvProductReceiveDetail != null)
                            {
                                objInvProductReceiveDetail.InvProductReceiveId = ProductRecievedobj.Id;
                                objInvProductReceiveDetail.SlsProductId = item.SlsProductId;
                                objInvProductReceiveDetail.ReceivedQuantity = item.ReceivedQuantity;
                                objInvProductReceiveDetail.IssuedQuantity = item.IssuedQuantity;
                                objInvProductReceiveDetail.SlsUnitId = item.SlsUnitId;
                                objInvProductReceiveDetail.Remarks = item.Remarks;
                                _ProductReceiveDetailService.Update(objInvProductReceiveDetail);
                            }
                            else
                            {
                                objInvProductReceiveDetail = new InvProductReceiveDetail();
                                objInvProductReceiveDetail.InvProductReceiveId = ProductRecievedobj.Id;
                                objInvProductReceiveDetail.SlsProductId = item.SlsProductId;
                                objInvProductReceiveDetail.ReceivedQuantity = item.ReceivedQuantity;
                                objInvProductReceiveDetail.IssuedQuantity = item.IssuedQuantity;
                                objInvProductReceiveDetail.SlsUnitId = item.SlsUnitId;
                                objInvProductReceiveDetail.Remarks = item.Remarks;
                                _ProductReceiveDetailService.Save(objInvProductReceiveDetail);
                            }

                        }

                    }
                }
                objOperation = _ProductReceiveService.Commit();

            }

            return Json(objOperation, JsonRequestBehavior.DenyGet);
        }
        public Operation Update(InvProductReceiveDetail objProductReceiveDetail)
        {
            Operation objOperation = new Operation { Success = true, OperationId = objProductReceiveDetail.Id };
               _ProductReceiveDetailRepository.Update(objProductReceiveDetail);

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

               }
               return objOperation;
        }