Beispiel #1
0
        public ActionResult Create(GetUnitCategory model)
        {
            tblCategory tb = new tblCategory();


            try
            {
                if (model.CategoryId > 0)
                {
                    tb           = (from p in db.tblCategories.Where(o => o.CategoryId == model.CategoryId) select p).SingleOrDefault();
                    tb.Name      = model.Name;
                    tb.Active    = model.Active;
                    tb.Color     = model.Color;
                    tb.TextColor = model.TextColor;
                    db.SaveChanges();
                    TempData["categroy"] = "Record Edit Successfully..!";
                    return(RedirectToAction("Index"));
                }
                else
                {
                    var cattableid = (from p in db.tblCategories where p.Name == model.Name select p).SingleOrDefault();
                    if (cattableid == null)
                    {
                        tb.Name      = model.Name;
                        tb.Active    = model.Active;
                        tb.Color     = model.Color;
                        tb.TextColor = model.TextColor;
                        db.tblCategories.Add(tb);
                        db.SaveChanges();
                        TempData["categroy"] = "Record Insert Successfully..!";
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        TempData["Crecategroy"] = "This Category is Already exist..!";
                        return(RedirectToAction("Create"));
                    }
                }
            }
            catch (Exception ex)
            {
                TempData["categroy"] = ex.Message;
                return(RedirectToAction("Create"));
            }
        }
Beispiel #2
0
 public ActionResult Create(int id = 0)
 {
     if (id > 0)
     {
         var             data  = (from p in db.tblCategories where p.CategoryId == id select p).SingleOrDefault();
         GetUnitCategory model = new GetUnitCategory();
         model.CategoryId = data.CategoryId;
         model.Name       = data.Name;
         model.Active     = data.Active;
         model.Color      = data.Color;
         model.TextColor  = data.TextColor;
         // model.Type = data.Type;
         return(View(model));
     }
     else
     {
         return(View());
     }
 }
Beispiel #3
0
        public ActionResult Index()
        {
            var subgrpKOT = (from p in dbKOT.VM_ItemSubGroups select p).ToList();

            foreach (var item in subgrpKOT)
            {
                var table = db.tblCategories.Where(a => a.Name == item.ItemSubGroup).FirstOrDefault();
                if (table == null)
                {
                    tblCategory tb = new tblCategory();
                    tb.Name   = item.ItemSubGroup;
                    tb.Active = true;
                    var random = new Random();
                    var color  = String.Format("#{0:X6}", random.Next(0x1000000));
                    tb.Color = color;
                    var forerandom = new Random();
                    color        = String.Format("#{0:X6}", forerandom.Next(0x1000000));
                    tb.TextColor = color;
                    db.tblCategories.Add(tb);
                    db.SaveChanges();
                }
            }



            var data = (from p in db.tblCategories where p.Active == true select p).ToList();
            List <GetUnitCategory> List = new List <GetUnitCategory>();

            foreach (var item in data)
            {
                GetUnitCategory model1 = new GetUnitCategory();
                model1.CategoryId = item.CategoryId;
                model1.Name       = item.Name;
                model1.Color      = item.Color;
                // model.Type = item.Type;
                List.Add(model1);
            }
            return(View(List));
        }