Beispiel #1
0
        public ActionResult Create([Bind(Include = "ID,Name,Activity_ID,ShortName,StateID")] Sub_Activity_Master sub_Activity_Master)
        {
            try
            {
                ViewBag.Activity_ID = new SelectList(db.Activity_Master.OrderBy(m => m.Name), "ID", "Name", sub_Activity_Master.Activity_ID);

                ViewBag.StateID = new SelectList(db.State_Master.OrderBy(s => s.Name), "ID", "Name", sub_Activity_Master.StateID);

                //if (ModelState.IsValid)
                //{
                var getName = db.Sub_Activity_Master.Where(u => u.Name == sub_Activity_Master.Name && u.Activity_ID == sub_Activity_Master.Activity_ID &&
                                                           u.StateID == sub_Activity_Master.StateID).ToList();

                if (getName.Count > 0)
                {
                    ViewBag.message = ToasterMessage.Message(ToastType.info, "Record already exist");
                    return(View());
                }
                else
                {
                    db.Sub_Activity_Master.Add(sub_Activity_Master);
                    db.SaveChanges();
                    TempData["message"] = ToasterMessage.Message(ToastType.success, "Saved successfully");
                    return(RedirectToAction("Index"));
                }
                //}
            }
            catch (DbEntityValidationException e)
            {
                string errorMessage = string.Empty;

                foreach (DbEntityValidationResult eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);

                    foreach (DbValidationError ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                        errorMessage = ve.ErrorMessage;

                        ViewBag.message = ViewBag.message + ToasterMessage.Message(ToastType.error, errorMessage);
                    }
                }
                return(View());
            }
            catch (Exception)
            {
                ViewBag.message = ToasterMessage.Message(ToastType.error, "Something went wrong");
            }

            return(View());
        }
Beispiel #2
0
        // GET: Sub_Activity_Master/Details/5
        public ActionResult Details(decimal?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Sub_Activity_Master sub_Activity_Master = db.Sub_Activity_Master.Find(id);

            if (sub_Activity_Master == null)
            {
                return(HttpNotFound());
            }

            return(View(sub_Activity_Master));
        }
Beispiel #3
0
        // GET: Sub_Activity_Master/Edit/5
        public ActionResult Edit(decimal?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Sub_Activity_Master sub_Activity_Master = db.Sub_Activity_Master.Find(id);

            if (sub_Activity_Master == null)
            {
                return(HttpNotFound());
            }

            ViewBag.Activity_ID = new SelectList(db.Activity_Master.OrderBy(m => m.Name), "ID", "Name", sub_Activity_Master.Activity_ID);
            ViewBag.StateID     = new SelectList(db.State_Master.OrderBy(s => s.Name), "ID", "Name", sub_Activity_Master.StateID);

            return(View(sub_Activity_Master));
        }
Beispiel #4
0
        public ActionResult DeleteConfirmed(decimal id)
        {
            try
            {
                Sub_Activity_Master sub_Activity_Master = db.Sub_Activity_Master.Find(id);
                db.Sub_Activity_Master.Remove(sub_Activity_Master);
                db.SaveChanges();
                TempData["message"] = ToasterMessage.Message(ToastType.success, "Deleted successfully");
                return(RedirectToAction("Index"));
            }
            catch (DbEntityValidationException e)
            {
                string errorMessage = string.Empty;

                foreach (DbEntityValidationResult eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);

                    foreach (DbValidationError ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                        errorMessage = ve.ErrorMessage;

                        ViewBag.message = ViewBag.message + ToasterMessage.Message(ToastType.error, errorMessage);
                    }
                }
                return(View());
            }
            catch (Exception)
            {
                ViewBag.message = ToasterMessage.Message(ToastType.error, "Something went wrong");
            }

            return(View());
        }