예제 #1
0
        public IHttpActionResult Create(Employee employee)
        {
            if (ModelState.IsValid)
            {
                User        user = new User();
                JobCategory job  = jobcatrepo.GetById(employee.JobId);
                user.UserName   = employee.UserName;
                user.Password   = employee.UserName;
                user.UserType   = job.JobTitle;
                user.UserStatus = employee.Status;
                employeerepo.Insert(employee);
                userrepo.Insert(user);
                var    emp = employeerepo.AddLink(employeerepo.GetByUserName(employee.UserName));
                string url = "http://localhost:51045/api/employees/" + emp.EmployeeId;
                return(Created("url", emp));
            }

            return(BadRequest(ModelState));
        }
 public ActionResult Create(Employee employee, HttpPostedFileBase image)
 {
     if (CheckAccess())
     {
         if (ModelState.IsValid)
         {
             var person = userrepo.GetByUserName(employee.UserName);
             if (person == null)
             {
                 if (image != null)
                 {
                     if (Path.GetExtension(image.FileName) == ".jpg" | Path.GetExtension(image.FileName) == ".png")
                     {
                         string name      = Path.GetFileNameWithoutExtension(image.FileName);
                         string extention = Path.GetExtension(image.FileName);
                         name = name + DateTime.Now.ToString("yyyy-MM-dd") + extention;
                         string ProfilePicture = "~/Content/ProfilePictures/" + name;
                         string filepath       = Path.Combine(Server.MapPath("~/Content/ProfilePictures/"), name);
                         image.SaveAs(filepath);
                         employee.ProfilePicture = ProfilePicture;
                         User        user = new User();
                         JobCategory job  = jobcatrepo.GetById(employee.JobId);
                         user.UserName   = employee.UserName;
                         user.Password   = employee.UserName;
                         user.UserType   = job.JobTitle;
                         user.UserStatus = employee.Status;
                         employeerepo.Insert(employee);
                         userrepo.Insert(user);
                         return(RedirectToAction("Index"));
                     }
                     else
                     {
                         TempData["Error2"]      = "Profile picture must need to be type '.jpg' or '.png'";
                         TempData["JobCategory"] = jobcatrepo.GetAll();
                         return(View(employee));
                     }
                 }
                 TempData["Error2"]      = "Must need to add a profile picture";
                 TempData["JobCategory"] = jobcatrepo.GetAll();
                 return(View(employee));
             }
             TempData["Error1"]      = "This username is taken";
             TempData["JobCategory"] = jobcatrepo.GetAll();
             return(View(employee));
         }
         TempData["JobCategory"] = jobcatrepo.GetAll();
         return(View(employee));
     }
     else
     {
         return(RedirectToAction("Login", "Home"));
     }
 }
예제 #3
0
 public IHttpActionResult GetProfile(string userType, string userName)
 {
     if (userType == "Customer")
     {
         var profile     = customerrepo.GetByUserName(userName);
         var profileview = new ProfileViewModel();
         profileview.Id             = profile.CustomerId;
         profileview.Name           = profile.CustomerName;
         profileview.UserName       = profile.UserName;
         profileview.Gender         = profile.Gender;
         profileview.Email          = profile.Email;
         profileview.DateOfBirth    = profile.DateOfBirth;
         profileview.Address        = profile.Address;
         profileview.ProfilePicture = profile.ProfilePicture;
         profileview.Status         = profile.Status;
         return(Ok(profileview));
     }
     else if (userType == "Vendor")
     {
         var profile     = vendorrepo.GetByUserName(userName);
         var profileview = new ProfileViewModel();
         profileview.Id             = profile.VendorId;
         profileview.Name           = profile.VendorName;
         profileview.UserName       = profile.UserName;
         profileview.Gender         = profile.Gender;
         profileview.Email          = profile.Email;
         profileview.DateOfBirth    = profile.DateOfBirth;
         profileview.Address        = profile.Address;
         profileview.ProfilePicture = profile.ProfilePicture;
         profileview.Status         = profile.Status;
         return(Ok(profileview));
     }
     else
     {
         var profile     = employeerepo.GetByUserName(userName);
         var jobDetails  = jobcatrepo.GetById((int)profile.JobId);
         var profileview = new ProfileViewModel();
         profileview.Id             = profile.EmployeeId;
         profileview.Name           = profile.EmployeeName;
         profileview.UserName       = profile.UserName;
         profileview.Gender         = profile.Gender;
         profileview.Email          = profile.Email;
         profileview.DateOfBirth    = profile.DateOfBirth;
         profileview.Address        = profile.Address;
         profileview.JoiningDate    = profile.JoiningDate;
         profileview.ProfilePicture = profile.ProfilePicture;
         profileview.JobId          = profile.JobId;
         profileview.Status         = profile.Status;
         return(Ok(new { profileview, jobDetails }));
     }
 }
 public ActionResult Index()
 {
     if (Session["UserType"].ToString() == "Customer")
     {
         var profile     = customerrepo.GetByUserName(Session["UserName"].ToString());
         var profileview = new ProfileViewModel();
         profileview.Id             = profile.CustomerId;
         profileview.Name           = profile.CustomerName;
         profileview.UserName       = profile.UserName;
         profileview.Gender         = profile.Gender;
         profileview.Email          = profile.Email;
         profileview.DateOfBirth    = profile.DateOfBirth;
         profileview.Address        = profile.Address;
         profileview.ProfilePicture = profile.ProfilePicture;
         profileview.Status         = profile.Status;
         return(View(profileview));
     }
     else if (Session["UserType"].ToString() == "Vendor")
     {
         var profile     = vendorrepo.GetByUserName(Session["UserName"].ToString());
         var profileview = new ProfileViewModel();
         profileview.Id             = profile.VendorId;
         profileview.Name           = profile.VendorName;
         profileview.UserName       = profile.UserName;
         profileview.Gender         = profile.Gender;
         profileview.Email          = profile.Email;
         profileview.DateOfBirth    = profile.DateOfBirth;
         profileview.Address        = profile.Address;
         profileview.ProfilePicture = profile.ProfilePicture;
         profileview.Status         = profile.Status;
         return(View(profileview));
     }
     else
     {
         var profile = employeerepo.GetByUserName(Session["UserName"].ToString());
         TempData["JobDetails"] = jobcatrepo.GetById((int)profile.JobId);
         var profileview = new ProfileViewModel();
         profileview.Id             = profile.EmployeeId;
         profileview.Name           = profile.EmployeeName;
         profileview.UserName       = profile.UserName;
         profileview.Gender         = profile.Gender;
         profileview.Email          = profile.Email;
         profileview.DateOfBirth    = profile.DateOfBirth;
         profileview.Address        = profile.Address;
         profileview.JoiningDate    = profile.JoiningDate;
         profileview.ProfilePicture = profile.ProfilePicture;
         profileview.JobId          = profile.JobId;
         profileview.Status         = profile.Status;
         return(View(profileview));
     }
 }