Esempio n. 1
0
        public async Task <IHttpActionResult> SetMainPhoto(int userId, int id)
        {
            //if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            //    return Unauthorized();

            var user = await _repo.GetUser(userId);

            if (!user.Photos.Any(p => p.Id == id))
            {
                return(Unauthorized());
            }

            var photoFromRepo = await _repo.GetPhoto(id);

            if ((bool)photoFromRepo.IsMain)
            {
                return(BadRequest("This is already the main photo"));
            }

            var currentMainPhoto = await _repo.GetMainPhotoForUser(userId);

            currentMainPhoto.IsMain = false;

            photoFromRepo.IsMain = true;

            db.Entry(photoFromRepo).State    = EntityState.Modified;        // data is updated in database
            db.Entry(currentMainPhoto).State = EntityState.Modified;        // data is updated in database


            await db.SaveChangesAsync();

            return(StatusCode(HttpStatusCode.NoContent));

            //return BadRequest("Could not set photo to main");
        }
        public ActionResult BuildSystem(int employeeID, string RAM, string HDDSize)
        {
            Employee       employee       = db.Employees.Find(employeeID);
            ComputerSystem computerSystem = new ComputerSystem(RAM, HDDSize);

            employee.SystemConfigurationDetails = computerSystem.Build();
            db.Entry(employee).State            = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "Id,Name,JobDesc,Number,Department,HourlyPay,Bonus,EmployeeTypeId")] Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.EmployeeTypeId = new SelectList(db.EmployeeTypes, "Id", "Types", employee.EmployeeTypeId);
     return(View(employee));
 }
        public ActionResult BuildLaptop(FormCollection formCollection)
        {
            Employee             employee             = db.Employees.Find(Convert.ToInt32(formCollection["employeeID"]));
            ISystemBuilder       systemBuilder        = new LaptopBuilder();
            ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.BuildSystem(systemBuilder, formCollection);

            ComputerSystem computerSystem = systemBuilder.GetComputerSystem();

            employee.SystemConfigurationDetails = string.Format("RAM : {0}, HDDSize : {1}, KeyBoard : {2}, Mouse : {3}, TouchScreen : {4}",
                                                                computerSystem.RAM, computerSystem.HDDSize, computerSystem.KeyBoard, computerSystem.Mouse, computerSystem.TouchScreen);

            db.Entry(employee).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 5
0
        public ActionResult BuildDesktop(FormCollection formcollection)
        {
            //Step 1
            Employee employee = db.Employees.Find(Convert.ToInt32(formcollection["employeeID"]));
            //Step 2 Concrete Build
            ISystemBuilder systemBuilder = new DesktopBuilder();
            //Step 3: Director
            ConfigurationBuilder builder = new ConfigurationBuilder();

            builder.BuildSystem(systemBuilder, formcollection);
            //Step 4: Reuturn System Built
            ComputerSystem system = systemBuilder.GetSystem();

            employee.SystemConfiguration = string.Format("RAM : {0}, Keyboard: {1}, Mouse: {2}, Touchscreen: {3}, HDDDrive: {4}",
                                                         system.RAM, system.KeyBoard, system.Mouse, system.TouchScreen, system.HDDSize);
            db.Entry(employee).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 6
0
 public ActionResult Edit([Bind(Include = "Id,Name,JobDescription,Number,Department")] Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(employee));
 }
 public ActionResult Edit([Bind(Include = "ID,Name,ManagerID,Active")] Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ManagerID = new SelectList(db.Managers, "ID", "Name", employee.ManagerID);
     return(View(employee));
 }
Esempio n. 8
0
 public ActionResult Edit([Bind(Include = "ID,Name,SeniorManagerID,Active")] Manager manager)
 {
     if (ModelState.IsValid)
     {
         db.Entry(manager).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.SeniorManagerID = new SelectList(db.Managers, "ID", "Name", manager.SeniorManagerID);
     return(View(manager));
 }
        public ActionResult BuildLaptop(FormCollection formCollection)
        {
            Employee employee = db.Employee.Find(Convert.ToInt32(formCollection["employeeID"]));

            //Concrete builder
            ISystemBuilder systemBuilder = new LaptopBuilder();

            //Director
            ConfigurationBuilder builder = new ConfigurationBuilder();

            builder.BuildSystem(systemBuilder, formCollection);

            ComputerSystem computerSystem = systemBuilder.GetSystem();

            employee.SystemConfigurationDetails =
                string.Format("Ram: {0}, HDDSize: {1}, TouchS: {2}",
                              computerSystem.RAM, computerSystem.HDDSize, computerSystem.TouchScreen);
            db.Entry(employee).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult BuildDesktop(FormCollection formCollection)
        {
            //step 1
            Employee employee = db.Employees.Find(Convert.ToInt32(formCollection["employeeID"]));
            //step 2 concrete builder
            ISystemBuilder systemBuilder = new DesktopBuilder();

            //step 3 Director
            ConfigurationBuilder builder = new ConfigurationBuilder();

            builder.BuildSystem(systemBuilder, formCollection);

            //step 4 return the system
            ComputerSystem system = systemBuilder.GetSystem();

            employee.SystemConfigurationDetails =
                string.Format("RAM:{0},HDDSize:{1},KeyBoard:{2},Mouse:{3}"
                              , system.RAM, system.HDDSize, system.KeyBoard, system.Mouse);
            db.Entry(employee).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 11
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Name,Number,DepartmentID,DesignationID,HourlyRate,Bonus,EmployeeTypeID")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Entry(employee).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.DepartmentID   = new SelectList(db.Departments, "Id", "DepartmentName", employee.DepartmentID);
            ViewBag.DesignationID  = new SelectList(db.Designations, "Id", "DesignationName", employee.DesignationID);
            ViewBag.EmployeeTypeID = new SelectList(db.EmployeeTypes, "Id", "EmployeeTypeName", employee.EmployeeTypeID);
            return(View(employee));
        }
Esempio n. 12
0
        //[Route("api/user")]
        public async Task <IHttpActionResult> GetUsers([FromUri] UserParams userParams)
        {
            var currentUserId = int.Parse(ClaimsPrincipal.Current.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value);

            var userFromRepo = await _repo.GetUser(currentUserId);

            userFromRepo.LastActive      = DateTime.Now;
            db.Entry(userFromRepo).State = EntityState.Modified;           // data is updated in database
            await db.SaveChangesAsync();

            userParams.UserId = currentUserId;
            // changes is commiteed in data base


            var users = await _repo.GetUsers(userParams);

            var usersToReturn = Mapper.Map <IEnumerable <UserForListDto> >(users);

            //HttpResponse Response=null;
            HttpContext.Current.Response.AddPagination(users.CurrentPage, users.PageSize, users.TotalCount, users.TotalPages);

            return(Ok(usersToReturn));
        }
Esempio n. 13
0
        public async Task <IHttpActionResult> GetMessage(int userId, int id)
        {
            var currentUserId = int.Parse(ClaimsPrincipal.Current.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value);

            var userFromRepo = await _repo.GetUser(currentUserId);

            userFromRepo.LastActive      = DateTime.Now;
            db.Entry(userFromRepo).State = EntityState.Modified;           // data is updated in database
            await db.SaveChangesAsync();

            var messageFromRepo = await _repo.GetMessage(id);

            if (messageFromRepo == null)
            {
                return(NotFound());
            }

            return(Ok(messageFromRepo));
        }