Exemplo n.º 1
0
        public ActionResult create()
        {
            try
            {
                ViewBag.rest     = dbcontext.Discipline_PunishmentRestOption.ToList().Select(m => new { Code = m.RestOption_Code + "-[" + m.RestOption_Desc + ']', ID = m.ID });
                ViewBag.group    = dbcontext.Discipline_PunishmentGroup.ToList().Select(m => new { Code = m.PunishmentGroup_Code + "-[" + m.PunishmentGroup_Desc + ']', ID = m.ID });
                ViewBag.penality = dbcontext.Discipline_PenaltyItem_Header.ToList().Select(m => new { Code = m.PenaltyItem_Code + "-[" + m.PenaltyItem_Desc + ']', ID = m.ID });

                var new_model = new Discipline_Punishment();
                var stru      = dbcontext.StructureModels.FirstOrDefault(m => m.All_Models == ChModels.Personnel).Structure_Code;
                var model     = dbcontext.Discipline_Punishment.ToList();
                if (model.Count() == 0)
                {
                    new_model.Punishment_Code = stru + "1";
                }
                else
                {
                    new_model.Punishment_Code = stru + (model.LastOrDefault().ID + 1).ToString();
                }
                /////

                return(View(new_model));
            }
            catch (Exception)
            {
                return(RedirectToAction("index"));
            }
        }
Exemplo n.º 2
0
        public ActionResult create(FormCollection form, Discipline_Punishment model)
        {
            try
            {
                ViewBag.rest     = dbcontext.Discipline_PunishmentRestOption.ToList().Select(m => new { Code = m.RestOption_Code + "-[" + m.RestOption_Desc + ']', ID = m.ID });
                ViewBag.group    = dbcontext.Discipline_PunishmentGroup.ToList().Select(m => new { Code = m.PunishmentGroup_Code + "-[" + m.PunishmentGroup_Desc + ']', ID = m.ID });
                ViewBag.penality = dbcontext.Discipline_PenaltyItem_Header.ToList().Select(m => new { Code = m.PenaltyItem_Code + "-[" + m.PenaltyItem_Desc + ']', ID = m.ID });

                //================================
                model.Created_By   = User.Identity.Name;
                model.Created_Date = DateTime.Now;
                var pun = dbcontext.Discipline_Punishment.Add(model);
                dbcontext.SaveChanges();
                //================================

                var center_D = form["center_id"].Split(',');
                for (var i = 0; i < center_D.Length; i++)
                {
                    if (center_D[i] != "")
                    {
                        var ID         = int.Parse(center_D[i]);
                        var CENTER     = dbcontext.Discipline_PenaltyItem_Header.FirstOrDefault(m => m.ID == ID);
                        var Cource_cen = new Discipline_Punishment_Detail {
                            penal_Des = CENTER.PenaltyItem_Code + "-" + CENTER.PenaltyItem_Desc, Created_By = User.Identity.Name, Created_Date = DateTime.Now.Date, PenaltyItem_Code = CENTER.ID.ToString(), Punishment_Code = pun.ID.ToString(), PenaltyItem_Level = (short)(i)
                        };
                        dbcontext.Discipline_Punishment_Detail.Add(Cource_cen);
                        dbcontext.SaveChanges();
                    }
                }
                //=================================check for alert==================================
                var get_result_check = HR.Controllers.check.check_alert("punishments", HR.Models.user.Action.Create, HR.Models.user.type_field.form);
                if (get_result_check != null)
                {
                    var inbox = new Models.user.Alert_inbox {
                        send_from_user_id = User.Identity.Name, send_to_user_id = get_result_check.send_to_ID_user, title = get_result_check.Subject, Subject = get_result_check.Message
                    };
                    if (get_result_check.until != null)
                    {
                        if (get_result_check.until.Value.Year != 0001)
                        {
                            inbox.until = get_result_check.until;
                        }
                    }
                    ApplicationDbContext dbcontext = new ApplicationDbContext();
                    dbcontext.Alert_inbox.Add(inbox);
                    dbcontext.SaveChanges();
                }
                //==================================================================================
                //================================

                return(RedirectToAction("Index"));
            }
            catch (DbUpdateException e)
            {
                TempData["Message"] = HR.Resource.Basic.thiscodeIsalreadyexists;
                return(View(model));
            }
            catch (Exception e)
            {
                return(View(model));
            }
        }