public Operation Delete(SlsSalesTarget objSlsSalesTarget)
        {
            Operation objOperation = new Operation { Success = true, OperationId = objSlsSalesTarget.Id };
            _SalesTargetRepository.Delete(objSlsSalesTarget);

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

                objOperation.Success = false;
            }
            return objOperation;
        }
        public Operation Save(SlsSalesTarget objSlsSalesTarget)
        {
            Operation objOperation = new Operation { Success = true };

            int lastId = _SalesTargetRepository.GetLastId(objSlsSalesTarget);
            objSlsSalesTarget.Id = lastId;
            objOperation.OperationId = lastId;

            _SalesTargetRepository.Add(objSlsSalesTarget);
            return objOperation;
        }
 public Operation Update(SlsSalesTarget objSlsSalesTarget)
 {
     Operation objOperation = new Operation { Success = true, OperationId = objSlsSalesTarget.Id };
     _SalesTargetRepository.Update(objSlsSalesTarget);
     return objOperation;
 }
        public ActionResult Save(SlsSalesTarget sTarget, List<SlsSalesTargetDetail> sTargetDetail)
        {
            int companyId = Convert.ToInt32(Session["companyId"]);
            int userId = Convert.ToInt32(Session["userId"]);
            Operation objOperation = new Operation { Success = false };
            if (ModelState.IsValid && sTargetDetail != null)
            {
                if (sTarget.Id == 0)
                {
                    if ((bool)Session["Add"])
                    {
                        sTarget.SecCompanyId = companyId;
                        sTarget.CreatedBy = userId;
                        sTarget.CreatedDate = DateTime.Now;
                        objOperation = _SalesTargetService.Save(sTarget);

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

                        foreach (var item in sTargetDetail)
                        {
                            SlsSalesTargetDetail objSlsSalesTargetDetail = _SalesTargetDetailService.GetById(item.Id);
                            if (objSlsSalesTargetDetail != null)
                            {
                                objSlsSalesTargetDetail.SlsSalesTargetId = sTarget.Id;
                                objSlsSalesTargetDetail.SlsProductId = item.SlsProductId;
                                objSlsSalesTargetDetail.Quantity = item.Quantity;
                                objSlsSalesTargetDetail.SlsUnitId = item.SlsUnitId;
                                _SalesTargetDetailService.Update(objSlsSalesTargetDetail);
                            }
                            else
                            {
                                objSlsSalesTargetDetail = new SlsSalesTargetDetail();
                                objSlsSalesTargetDetail.SlsSalesTargetId = SalesTargetId;
                                objSlsSalesTargetDetail.SlsProductId = item.SlsProductId;
                                objSlsSalesTargetDetail.Quantity = item.Quantity;
                                objSlsSalesTargetDetail.SlsUnitId = item.SlsUnitId;
                                _SalesTargetDetailService.Save(objSlsSalesTargetDetail);
                            }

                        }

                    }

                }
                else
                {
                    if ((bool)Session["Edit"])
                    {
                        sTarget.SecCompanyId = companyId;
                        sTarget.ModifiedBy = userId;
                        sTarget.ModifiedDate = DateTime.Now;
                        objOperation = _SalesTargetService.Update(sTarget);

                        foreach (var item in sTargetDetail)
                        {
                            SlsSalesTargetDetail objSlsSalesTargetDetail = _SalesTargetDetailService.GetById(item.Id);
                            if (objSlsSalesTargetDetail != null)
                            {
                                objSlsSalesTargetDetail.SlsSalesTargetId = sTarget.Id;
                                objSlsSalesTargetDetail.SlsProductId = item.SlsProductId;
                                objSlsSalesTargetDetail.Quantity = item.Quantity;
                                objSlsSalesTargetDetail.SlsUnitId = item.SlsUnitId;
                                _SalesTargetDetailService.Update(objSlsSalesTargetDetail);
                            }
                            else
                            {
                                objSlsSalesTargetDetail = new SlsSalesTargetDetail();
                                objSlsSalesTargetDetail.SlsSalesTargetId = sTarget.Id;
                                objSlsSalesTargetDetail.SlsProductId = item.SlsProductId;
                                objSlsSalesTargetDetail.Quantity = item.Quantity;
                                objSlsSalesTargetDetail.SlsUnitId = item.SlsUnitId;
                                _SalesTargetDetailService.Save(objSlsSalesTargetDetail);
                            }

                        }

                    }

                }

                objOperation = _SalesTargetService.Commit();

            }

            return Json(objOperation, JsonRequestBehavior.DenyGet);
        }