Exemplo n.º 1
0
        public async Task <IHttpActionResult> AddPhotoForUser(int userId
                                                              /*[FromBody]PhotoForCreationDto photoForCreationDto*/)
        {
            Account acc = new Account(
                "vatsac",
                "936419744999822",
                "w39XjwviejNAug2X74Hfg2I7_qg"
                );

            var _cloudinary = new Cloudinary(acc);

            var userFromRepo = await _repo.GetUser(userId);

            var file = System.Web.HttpContext.Current.Request.Files.Count > 0 ?
                       HttpContext.Current.Request.Files[0] : null;

            var uploadResult = new ImageUploadResult();

            if (file.ContentLength > 0)
            {
                using (var stream = file.InputStream)
                {
                    var uploadParams = new ImageUploadParams()
                    {
                        File           = new FileDescription(file.FileName, stream),
                        Transformation = new Transformation()
                                         .Width(500).Height(500).Crop("fill").Gravity("face")
                    };

                    uploadResult = _cloudinary.Upload(uploadParams);
                };
            }

            var photoForCreationDto = new PhotoForCreationDto
            {
                File     = file,
                Url      = uploadResult.Uri.ToString(),
                PublicId = uploadResult.PublicId,
                UserId   = userId
            };

            var photo = Mapper.Map <Photo>(photoForCreationDto);

            if (!userFromRepo.Photos.Any(u => (bool)u.IsMain))
            {
                photo.IsMain = true;
            }
            else
            {
                photo.IsMain = false;
            }

            db.Photos.Add(photo);
            await db.SaveChangesAsync();

            var photoToReturn = Mapper.Map <PhotoForReturnDto>(photo);

            return(CreatedAtRoute("GetPhoto", new { userId, id = photo.Id }, photoToReturn));
        }
Exemplo n.º 2
0
 public async Task <bool> SaveAll()
 {
     using (EmployeePortalEntities _context = new EmployeePortalEntities())
     {
         return(await _context.SaveChangesAsync() > 0);
     }
 }
Exemplo n.º 3
0
        public async Task <ActionResult> Create([Bind(Include = "Id,Name,Number,DepartmentID,DesignationID,EmployeeTypeID")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                BaseEmployeeFactory bEmpFact = new EmployeeManagerFactory().GetFactory(employee);
                bEmpFact.CalculateSalary();
                db.Employees.Add(employee);
                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));
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
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));
        }
Exemplo n.º 6
0
        public async Task<User> Register(User user, string password)
        {
            using (EmployeePortalEntities _context = new EmployeePortalEntities())
            {
                byte[] passwordHash, passwordSalt;
                CreatePasswordHash(password, out passwordHash, out passwordSalt);

                user.PasswordHash = passwordHash;
                user.PasswordSalt = passwordSalt;

                _context.Users.Add(user);
                await _context.SaveChangesAsync();

                return user;
            }
        }