public ActionResult Entry(AssetEntryVm assetEntryVm)
        {
            ViewBag.orglist = generalCategoryManager.GetAll();

            ViewBag.assetlist = assetManager.GetSome(5);

            var assetCodeCheck = assetManager.GetAll().Where(c => c.Code == assetEntryVm.Code).ToList();

            if (!ModelState.IsValid)
            {
                return(View(assetEntryVm));
            }
            else if (assetCodeCheck.Count > 0)
            {
                ViewBag.msg = "Code Already Exist";
                return(View(assetEntryVm));
            }
            else
            {
                var assetEntry = Mapper.Map <Asset>(assetEntryVm);
                assetEntry.Registered   = false;
                assetEntry.Organization = Session["organizationName"].ToString();
                assetManager.Add(assetEntry);

                //var newAssetEntry = Mapper.Map<NewAsset>(assetEntryVm);
                //newAssetManager.Add(newAssetEntry);

                ModelState.Clear();
                return(RedirectToAction("Entry", new { success = "true" }));
            }
        }
Example #2
0
        public ICollection <AssetEntryVm> GetAllAssetWithGeneral_Category_SubCategory_Brand_Product(string org)
        {
            var joinlist = from a in Context.Asset.Where(c => c.Registered == false && c.Organization == org)
                           join b in Context.Brand
                           on a.BrandId equals b.Id
                           join c in Context.Category
                           on b.CategoryId equals c.Id
                           join gc in Context.GeneralCategory
                           on c.GeneralCategoryId equals gc.Id

                           select new
            {
                id               = a.Id,
                code             = a.Code,
                serialno         = a.SerialNo,
                name             = a.Name,
                price            = a.Price,
                description      = a.Description,
                generalcategoyid = gc.Id,
                generalcategory  = gc.Name,
                categoryid       = c.Id,
                category         = c.Name,
                brandid          = b.Id,
                brand            = b.Name
            };

            ICollection <AssetEntryVm> list = new List <AssetEntryVm>();

            foreach (var t in joinlist)
            {
                AssetEntryVm assetvm = new AssetEntryVm();
                assetvm.Id                  = t.id;
                assetvm.Code                = t.code;
                assetvm.SerialNo            = t.serialno;
                assetvm.Name                = t.name;
                assetvm.Price               = t.price;
                assetvm.Description         = t.description;
                assetvm.GeneralCategoryId   = t.generalcategoyid;
                assetvm.GeneralCategoryName = t.generalcategory;
                assetvm.CategoryId          = t.categoryid;
                assetvm.CategoryName        = t.category;
                assetvm.BrandId             = t.brandid;
                assetvm.BrandName           = t.brand;
                list.Add(assetvm);
            }
            return(list.ToList());
        }
Example #3
0
        public ICollection <AssetEntryVm> GetSome(int n)
        {
            var join = from a in Context.Asset.Where(c => c.Registered == false)
                       join b in Context.Brand
                       on a.BrandId equals b.Id
                       join c in Context.Category
                       on b.CategoryId equals c.Id
                       join gc in Context.GeneralCategory
                       on c.GeneralCategoryId equals gc.Id

                       select new
            {
                id              = a.Id,
                code            = a.Code,
                serialno        = a.SerialNo,
                name            = a.Name,
                price           = a.Price,
                description     = a.Description,
                generalcategory = gc.Name,
                category        = c.Name,
                brand           = b.Name,
            };

            var joinlist = join.Take(n).OrderByDescending(c => c.id).ToList();
            ICollection <AssetEntryVm> list = new List <AssetEntryVm>();

            foreach (var t in joinlist)
            {
                AssetEntryVm assetvm = new AssetEntryVm();
                assetvm.Id                  = t.id;
                assetvm.Code                = t.code;
                assetvm.SerialNo            = t.serialno;
                assetvm.Name                = t.name;
                assetvm.Price               = t.price;
                assetvm.Description         = t.description;
                assetvm.GeneralCategoryName = t.generalcategory;
                assetvm.CategoryName        = t.category;
                assetvm.BrandName           = t.brand;
                list.Add(assetvm);
            }
            return(list.ToList());
        }