public int InsertSupplierItemRate(SupplierItemRate objSupplierItemRate)
        {
            using (IDbConnection connection = OpenConnection(dataConnection))
            {
                int id = 0;
                foreach (var item in objSupplierItemRate.SupplierItemRateItem)
                {
                    string sql = @"insert  into SupplierItemRate(SupplierId,ItemId,FixedRate,EffectiveDate,CreatedBy,CreatedDate,OrganizationId,isActive) 
                           Values (@SupplierId,@ItemId,@FixedRate,@CreatedDate,@CreatedBy,@CreatedDate,@OrganizationId,1);
                           SELECT CAST(SCOPE_IDENTITY() as int)";

                    //id = connection.Query<int>(sql, objOpeningStock).Single();

                    id = connection.Query <int>(sql, new
                    {
                        SupplierId     = objSupplierItemRate.SupplierId,
                        ItemId         = item.ItemId,
                        FixedRate      = item.FixedRate,
                        CreatedBy      = objSupplierItemRate.CreatedBy,
                        EffectiveDate  = objSupplierItemRate.CreatedDate,
                        CreatedDate    = objSupplierItemRate.CreatedDate,
                        OrganizationId = objSupplierItemRate.OrganizationId
                    }).Single();
                }


                return(id);
            }
        }
 public int DeleteSupplierItemRate(SupplierItemRate objSupplierItemRate)
 {
     using (IDbConnection connection = OpenConnection(dataConnection))
     {
         string sql = @"Delete From  SupplierItemRate  WHERE SupplierId=@SupplierId";
         var    id  = connection.Execute(sql, objSupplierItemRate);
         return(id);
     }
 }
        public ActionResult Create()
        {
            FillSupplier();

            SupplierItemRate SupplierItemRate = new SupplierItemRate();

            SupplierItemRate.SupplierItemRateItem = new List <SupplierItemRateItem>();
            SupplierItemRate.SupplierItemRateItem.Add(new SupplierItemRateItem());

            return(View(SupplierItemRate));
        }
        public ActionResult Save(SupplierItemRate model)
        {
            model.OrganizationId = OrganizationId;
            model.CreatedDate    = System.DateTime.Now;
            model.CreatedBy      = UserID.ToString();
            new SupplierItemRateRepository().DeleteSupplierItemRate(model);
            new SupplierItemRateRepository().InsertSupplierItemRate(model);

            FillSupplier();
            FillItem();

            SupplierItemRate SupplierItemRate = new SupplierItemRate();

            SupplierItemRate.SupplierItemRateItem = new List <SupplierItemRateItem>();
            SupplierItemRate.SupplierItemRateItem.Add(new SupplierItemRateItem());
            //return View("Create");
            TempData["Success"]    = "Updated Successfully!";
            TempData["SupplierId"] = model.SupplierId;
            return(RedirectToAction("Create"));
        }
        public ActionResult SupplierItemRateList(int?SupplierId)
        {
            FillItem();

            SupplierItemRate SupplierItemRate = new SupplierItemRate();

            SupplierItemRate.SupplierItemRateItem = new List <SupplierItemRateItem>();
            if (SupplierId == null || SupplierId == 0)
            {
                var SupplierItemRateItem = new SupplierItemRateItem();
                SupplierItemRate.SupplierItemRateItem.Add(SupplierItemRateItem);
            }
            else
            {
                var repo = new SupplierItemRateRepository();
                SupplierItemRate.SupplierItemRateItem = repo.GetItem(SupplierId).ToList();
            }

            if (SupplierItemRate.SupplierItemRateItem.Count == 0)
            {
                SupplierItemRate.SupplierItemRateItem.Add(new SupplierItemRateItem());
            }
            return(PartialView("SupplierItemRateList", SupplierItemRate));
        }