Esempio n. 1
0
        public ActionResult Create(string id)
        {
            ViewBag.Employee_Profile = dbcontext.Employee_Profile.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID });
            ViewBag.idemp            = id;
            var stru  = dbcontext.StructureModels.FirstOrDefault(m => m.All_Models == ChModels.Personnel);
            var model = dbcontext.Employee_military_service_calling.ToList();
            var count = 0;

            if (model.Count() == 0)
            {
                count = 1;
            }
            else
            {
                var te = model.LastOrDefault().ID;
                count = te + 1;
            }
            DateTime statis2 = Convert.ToDateTime("1/1/1900");
            var      ID      = int.Parse(id);
            var      emp     = dbcontext.Employee_Profile.FirstOrDefault(m => m.ID == ID);
            var      Employee_military_service_calling = new Employee_military_service_calling {
                Code = stru.Structure_Code + count, Employee_ProfileId = emp.ID.ToString(), Start_date = DateTime.Now, End_date = DateTime.Now, Employee_Profile = emp
            };

            return(View(Employee_military_service_calling));
        }
Esempio n. 2
0
        public ActionResult Create(Employee_military_service_calling model, string command)
        {
            try
            {
                ViewBag.Employee_Profile = dbcontext.Employee_Profile.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID });

                //if (ModelState.IsValid)
                //{
                //    var con = int.Parse(model.Employee_ProfileId);
                //      var emp = dbcontext.Employee_Profile.FirstOrDefault(m => m.ID == con);
                var EmpObj = dbcontext.Employee_Profile.FirstOrDefault(a => a.ID == model.Employee_Profile.ID);

                Employee_military_service_calling record = new Employee_military_service_calling();
                var empid = EmpObj.Code + "------" + EmpObj.Name;
                record.Employee_ProfileId = model.Employee_ProfileId == null ? model.Employee_ProfileId = EmpObj.ID.ToString() : model.Employee_ProfileId;
                ViewBag.idemp             = model.Employee_ProfileId;
                record.Employee_Profile   = EmpObj;

                record.Code       = model.Code;
                record.Years      = model.Years;
                record.Months     = model.Months;
                record.Start_date = model.Start_date;
                record.End_date   = model.End_date;
                if (model.Start_date > model.End_date)
                {
                    TempData["Message"] = HR.Resource.Personnel.FromdatebiggerTodate;
                    return(View(model));
                }
                record.Days     = model.Days;
                record.Comments = model.Comments;



                var pos = dbcontext.Employee_military_service_calling.Add(record);
                dbcontext.SaveChanges();

                if (command == "Submit")
                {
                    return(RedirectToAction("edit", "Employee_Profile", new { id = EmpObj.ID }));
                }
                return(RedirectToAction("Index", new { id = EmpObj.ID }));
                //}
                //else
                //{
                //    return View(model);
                //}
            }
            catch (DbUpdateException e)
            {
                TempData["Message"] = HR.Resource.Basic.thiscodeIsalreadyexists;
                return(View(model));
            }
            catch (Exception e)
            {
                return(View(model));
            }
        }