예제 #1
0
        public ActionResult Create(string txt)
        {
            Comment comments = new Comment();

            comments.comment = txt;
            HttpCookie reqCookies = Request.Cookies["userInfo"];
            HttpCookie reqJobId   = Request.Cookies["JobId"];

            comments.JobId     = Convert.ToInt32(reqJobId["JobId"].ToString());
            comments.Profileid = Convert.ToInt32(reqCookies["Id"].ToString());
            if (ModelState.IsValid)
            {
                db.Comments.Add(comments);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            //ViewBag.JobId = new SelectList(db.Jobs, "Id", "Position", comment.JobId);
            //ViewBag.Profileid = new SelectList(db.Profiles, "Id", "Username", comment.Profileid);
            return(View(/*comment*/));
        }
 public ViewResult CreateEmploymentData(EmploymentData EmpData)
 {
     try
     {
         objDb.EmploymentDatas.Add(EmpData);
         objDb.SaveChanges();
         return(View("success"));
     }
     catch (Exception ex)
     {
         ViewBag.Error = ex.ToString();
         return(View("error"));
     }
 }
 public IEmployeeContract CreateEmployee(string firstName, string lastName, string middleName, DateTime birthDate)
 {
     using (EmploymentContext ctx = new EmploymentContext())
     {
         Employee emp = new Employee()
         {
             FirstName  = firstName,
             LastName   = lastName,
             MiddleName = middleName,
             BirthDate  = birthDate
         };
         ctx.Employees.Add(emp);
         int numObjectsSaved = ctx.SaveChanges();
         if (numObjectsSaved == 1)
         {
             return(new EmployeeContract(emp));
         }
     }
     return(null);
 }
예제 #4
0
        public ActionResult Create([Bind(Include = "Id,Username,Password,eAddress,Name,Surname,Role")] Profile profile)
        {
            if (ModelState.IsValid)
            {
                var user  = db.Profiles.Where(x => x.Username == profile.Username).FirstOrDefault();
                var user2 = db.Profiles.Where(x => x.eAddress == profile.eAddress).FirstOrDefault();
                if (user == null && user2 == null)
                {
                    db.Profiles.Add(profile);
                    db.SaveChanges();
                    HttpCookie userInfo = new HttpCookie("userInfo");
                    userInfo["UserName"] = profile.Username;
                    userInfo["Id"]       = profile.Id.ToString();
                    userInfo["Role"]     = profile.Role.ToString();
                    userInfo["Name"]     = profile.Name;
                    userInfo["Surname"]  = profile.Surname;
                    userInfo["eAddress"] = profile.eAddress;
                    userInfo.Expires.Add(new TimeSpan(0, 1, 0));
                    Response.Cookies.Add(userInfo);
                    return(RedirectToAction("AllJobs", "Jobs"));
                }
                else
                {
                    if (user != null)
                    {
                        ModelState.AddModelError("", "Username allready exists");
                    }
                    else if (user2 != null)
                    {
                        ModelState.AddModelError("", "Email allready exists");
                    }
                    return(View());
                }
            }

            return(View(profile));
        }