Beispiel #1
0
        public ActionResult Create()
        {
            //////
            var i = (Int16)group_purpose.Penalties.GetHashCode();

            ViewBag.credit = dbcontext.SalaryCodeGroup_Header.Where(m => m.GroupPurpose == i).ToList().Select(m => new { Code = m.CodeGroupID + "-[" + m.CodeGroupDesc + ']', ID = m.ID });

            var modell = new Discipline_PenaltyItem_Header();

            var stru  = dbcontext.StructureModels.FirstOrDefault(m => m.All_Models == ChModels.Personnel).Structure_Code;
            var model = dbcontext.Discipline_PenaltyItem_Header.ToList();

            if (model.Count() == 0)
            {
                modell.PenaltyItem_Code = stru + "1";
            }
            else
            {
                modell.PenaltyItem_Code = stru + (model.LastOrDefault().ID + 1).ToString();
            }
            /////
            return(View(modell));
        }
Beispiel #2
0
        public ActionResult Create(Discipline_PenaltyItem_Header model, FormCollection form, string commend)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var i = (Int16)group_purpose.Penalties.GetHashCode();
                    ViewBag.credit = dbcontext.SalaryCodeGroup_Header.Where(m => m.GroupPurpose == i).ToList().Select(m => new { Code = m.CodeGroupID + "-[" + m.CodeGroupDesc + ']', ID = m.ID });

                    model.Created_By   = User.Identity.Name;
                    model.Created_Date = DateTime.Now.Date;
                    var a1 = form["check_A"].Split(',');
                    if (a1.Length == 1)
                    {
                        model.LinkToPayroll = false;
                        model.CodeGroupID   = null;
                    }
                    else
                    {
                        model.LinkToPayroll = true;
                        model.CodeGroupID   = model.CodeGroupID;
                    }

                    var tra_center = dbcontext.Discipline_PenaltyItem_Header.Add(model);
                    //=================================check for alert==================================
                    var get_result_check = HR.Controllers.check.check_alert("penality items", 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();
                    }
                    //==================================================================================
                    dbcontext.SaveChanges();
                    if (commend == "payroll")
                    {
                        if (tra_center.LinkToPayroll == true && tra_center.CodeGroupID != null)
                        {
                            return(RedirectToAction("linkwithpayroll", new { header_id = tra_center.ID, path = 0 }));
                        }
                        else
                        {
                            TempData["Message"] = "You must choose sallary item group";
                            return(RedirectToAction("edit", new { id = tra_center.ID }));
                        }
                    }
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View(model));
                }
            }
            catch (DbUpdateException e)
            {
                TempData["Message"] = HR.Resource.Basic.thiscodeIsalreadyexists;
                return(View(model));
            }
            catch (Exception e)
            {
                return(View(model));
            }
        }