public Item GetItem(int id)
        {
            ItemRepo repo = new ItemRepo();

            _i = repo.GetItemById(id);
            return(_i);
        }
Exemple #2
0
        public ActionResult Edit(int id, FormCollection frm, string[] hddrowpindex)
        {
            var ses   = sesrepo.GetSessionById((User as CustomPrincipal).UserId);
            int orgid = ses.OrganizationId;

            try
            {
                MS_Item item = db.GetItemById(id);// (Convert.ToInt32(frm["ItemId"]));
                item.ItemName = frm["ItemName"];
                //item.ItemCode = frm["ItemCode"];
                //item.ItemDescription = frm["ItemDescription"];
                item.OrganizationId  = orgid;// Convert.ToInt32(frm["OrganizationId"]);
                item.CategoryId      = Convert.ToInt32(frm["CategoryId"]);
                item.LastUpdatedBy   = (User as CustomPrincipal).UserId;
                item.LastUpdatedDate = DateTime.Now;
                db.UpdateItem(item);
                iu.DeleteAllItemUnitByItem(item.ItemId, 0, DateTime.Now);
                MS_ItemUnit uitem;
                if (hddrowpindex != null && hddrowpindex.Count() > 0)
                {
                    foreach (var unititem in hddrowpindex)
                    {
                        if (frm["ItemUnitId-" + unititem] != "0")
                        {
                            uitem = iu.GetItemUnitById(Convert.ToInt32(frm["ItemUnitId-" + unititem]));
                        }
                        else
                        {
                            uitem = new MS_ItemUnit();
                        }
                        uitem.UnitId           = Convert.ToInt32(frm["UnitId-" + unititem]);
                        uitem.UnitSellingPrice = Convert.ToDecimal(frm["SellingPrice-" + unititem]);
                        uitem.QuantityInPiece  = Convert.ToInt32(frm["QuantityPer-" + unititem]);
                        if (frm["IsDefault-" + unititem] != null)
                        {
                            uitem.IsDefault = true;
                        }
                        else
                        {
                            uitem.IsDefault = false;
                        }
                        uitem.OrganizationId = item.OrganizationId;
                        uitem.ItemId         = item.ItemId;
                        if (frm["ItemUnitId-" + unititem] != "0")
                        {
                            iu.UpdateItemUnit(uitem);
                        }
                        else
                        {
                            iu.InsertItemUnit(uitem);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //ViewBag.UnitList = udb.GetUnitList(0, "", "");
                //ViewBag.CategoryId = new SelectList(ddl.GetCategoryList(), "Id", "Name", frm["CategoryId"]);
                //ViewBag.OrganizationId = new SelectList(ddl.GetOrganizationList(), "Id", "Name", frm["OrganizationId"]);

                return(RedirectToAction("Edit", new { id = frm["ItemId"] }));
            }
            //ViewBag.UnitList = udb.GetUnitList(0, "", "");
            //ViewBag.CategoryId = new SelectList(ddl.GetCategoryList(), "Id", "Name", frm["CategoryId"]);
            //ViewBag.OrganizationId = new SelectList(ddl.GetOrganizationList(), "Id", "Name", frm["OrganizationId"]);
            return(RedirectToAction("Index"));
        }