コード例 #1
0
        public ActionResult Create(string id)
        {
            ViewBag.Country          = dbcontext.Country.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID });
            ViewBag.Area             = dbcontext.Area.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID });
            ViewBag.the_states       = dbcontext.the_states.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID });
            ViewBag.Territories      = dbcontext.Territories.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID });
            ViewBag.cities           = dbcontext.cities.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID });
            ViewBag.postcode         = dbcontext.postcode.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID });
            ViewBag.Employee_Profile = dbcontext.Applicant_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.Recuirtment);
            var model = dbcontext.Applicant_Address_Profile.ToList();
            var count = 0;

            if (model.Count() == 0)
            {
                count = 1;
            }
            else
            {
                var te = model.LastOrDefault().ID;
                count = te + 1;
            }

            var ID  = int.Parse(id);
            var emp = dbcontext.Applicant_Profile.FirstOrDefault(m => m.ID == ID);
            var Applicant_Address = new Applicant_Address_Profile {
                Applicant_Profile = emp, Employee_ProfileId = emp.ID.ToString(), Code = stru.Structure_Code + count.ToString()
            };

            return(View(Applicant_Address));
        }
コード例 #2
0
        public ActionResult Create(Applicant_Address_Profile model, string command)
        {
            try
            {
                if (model.countryid == 0)
                {
                    model.countryid = null;
                }
                if (model.areaid == 0)
                {
                    model.areaid = null;
                }
                if (model.stateid == 0)
                {
                    model.stateid = null;
                }
                if (model.Territoriesid == 0)
                {
                    model.Territoriesid = null;
                }
                if (model.citiesid == 0)
                {
                    model.citiesid = null;
                }
                if (model.postcodeId == 0)
                {
                    model.postcodeId = null;
                }
                ViewBag.Employee_Profile = dbcontext.Applicant_Profile.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID });
                ViewBag.Country          = dbcontext.Country.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID });
                ViewBag.Area             = dbcontext.Area.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID });
                ViewBag.the_states       = dbcontext.the_states.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID });
                ViewBag.Territories      = dbcontext.Territories.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID });
                ViewBag.cities           = dbcontext.cities.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID });
                ViewBag.postcode         = dbcontext.postcode.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID });

                var EmpObj = dbcontext.Applicant_Profile.FirstOrDefault(a => a.ID == model.Applicant_Profile.ID);
                var list   = dbcontext.Applicant_Address_Profile.ToList();

                Applicant_Address_Profile record = new Applicant_Address_Profile();
                if (list.Count() == 0)
                {
                    record.Resident = true;
                }
                else
                {
                    var te = list.LastOrDefault();
                    te.Resident     = false;
                    record.Resident = true;
                }

                record.Code         = model.Code;
                record.Streetname   = model.Streetname;
                record.Streetnumber = model.Streetnumber;
                record.Pobox        = model.Pobox;
                record.DistancefromMeetingpointtoworklocationkm = model.DistancefromMeetingpointtoworklocationkm;
                record.Distancetoworklocationkm = model.Distancetoworklocationkm;
                record.Transportation_method    = model.Transportation_method;

                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.Applicant_Profile  = EmpObj;

                record.countryid     = model.countryid;
                record.areaid        = model.areaid;
                record.stateid       = model.stateid;
                record.Territoriesid = model.Territoriesid;
                record.citiesid      = model.citiesid;
                record.postcodeId    = model.postcodeId;
                dbcontext.Applicant_Address_Profile.Add(record);
                dbcontext.SaveChanges();
                if (command == "Submit")
                {
                    return(RedirectToAction("edit", "Applicant_Profile", new { id = EmpObj.ID }));
                }
                return(RedirectToAction("Index", new { id = EmpObj.ID }));

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