public async Task <IActionResult> PutLevel(int id, Level level)
        {
            if (id != level.Id)
            {
                return(BadRequest());
            }

            _context.Entry(level).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LevelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok());
        }
Exemple #2
0
        public async Task <IActionResult> PutPayform(int id, Payform payform)
        {
            if (id != payform.Id)
            {
                return(BadRequest());
            }

            _context.Entry(payform).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PayformExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok());
        }
Exemple #3
0
        public async Task <IActionResult> PutTypeOfWork(int id, TypeOfWork typeOfWork)
        {
            if (id != typeOfWork.Id)
            {
                return(BadRequest());
            }

            _context.Entry(typeOfWork).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TypeOfWorkExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok());
        }
Exemple #4
0
        public async Task <IActionResult> PutService(int id, [FromBody] string name)
        {
            var service = _context.Services.Find(id);

            service.Name = name;
            _context.Entry(service).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ServiceExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok());
        }
        public async Task <IActionResult> PutBank(int id, Bank bank)
        {
            if (id != bank.Id)
            {
                return(BadRequest());
            }

            _context.Entry(bank).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BankExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #6
0
        public async Task <IActionResult> PutProvince(string id, Province province)
        {
            if (id != province.ProvinceId)
            {
                return(BadRequest());
            }

            _context.Entry(province).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProvinceExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok());
        }
Exemple #7
0
        public async Task <IActionResult> PutSpecialty(int id, SpecialtyPModel specialtyPutModel)
        {
            var specialty = _context.Specialties.Find(id);

            if (specialty == null)
            {
                return(NotFound());
            }
            //create image
            string newname = "";

            if (specialtyPutModel.ImageBase64 != "")
            {
                string rootpath = _webHostEnvironment.WebRootPath;

                var nameDelete = specialty.Image
                                 .Substring(specialty.Image.LastIndexOf("/") + 1);
                try
                {
                    System.IO.File.Delete(rootpath + "\\Images\\" + nameDelete);
                }
                catch (Exception) { }

                newname = specialtyPutModel.ImageName + "_" + id;

                using (FileStream fs = System.IO.File.Create(rootpath + "\\Assets\\" + newname))
                {
                    fs.Close();
                    System.IO.File.WriteAllBytes(rootpath + "\\Images" + newname, Convert.FromBase64String(specialtyPutModel.ImageBase64));
                }
            }


            specialty.Name  = specialtyPutModel.Name;
            specialty.Image = "freelancervn.somee.com/api/images/assets/" + newname;
            _context.Entry(specialtyPutModel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SpecialtyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok());
        }
        public async Task <IActionResult> PutOfferHistory(int id, int freelancerid)
        {
            Job job = await _context.Jobs
                      .Include(p => p.OfferHistories).ThenInclude(p => p.Freelancer)
                      .Include(p => p.Renter)
                      .SingleOrDefaultAsync(p => p.Id == id);

            if (job == null)
            {
                NotFound();
            }

            String jwt = Request.Headers["Authorization"];

            jwt = jwt.Substring(7);
            //Decode jwt and get payload
            var stream    = jwt;
            var handler   = new JwtSecurityTokenHandler();
            var jsonToken = handler.ReadToken(stream);
            var tokenS    = jsonToken as JwtSecurityToken;
            //I can get Claims using:
            var email   = tokenS.Claims.First(claim => claim.Type == "email").Value;
            var account = job.Renter;

            if (account.Email != email)
            {
                return(BadRequest());
            }
            job.Status                = "In progress";
            job.FreelancerId          = freelancerid;
            _context.Entry(job).State = EntityState.Modified;
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!JobExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(Ok());
        }
        public async Task <IActionResult> PutSkill(int id, [FromBody] string name)
        {
            var skill = await _context.Skills.FindAsync(id);

            if (skill == null)
            {
                BadRequest();
            }

            String jwt = Request.Headers["Authorization"];

            jwt = jwt.Substring(7);
            //Decode jwt and get payload
            var stream    = jwt;
            var handler   = new JwtSecurityTokenHandler();
            var jsonToken = handler.ReadToken(stream);
            var tokenS    = jsonToken as JwtSecurityToken;
            //I can get Claims using:
            var email = tokenS.Claims.First(claim => claim.Type == "email").Value;
            var admin = await _context.Accounts
                        .SingleOrDefaultAsync(p => p.Email == email && p.RoleId == 1);

            if (admin == null)
            {
                return(BadRequest());
            }

            skill.Name = name;
            _context.Entry(skill).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SkillExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok());
        }
        public IActionResult PostAvatar([FromBody] ImageModel imageModel)
        {
            String jwt = Request.Headers["Authorization"];

            jwt = jwt.Substring(7);
            //Decode jwt and get payload
            var stream    = jwt;
            var handler   = new JwtSecurityTokenHandler();
            var jsonToken = handler.ReadToken(stream);
            var tokenS    = jsonToken as JwtSecurityToken;
            //I can get Claims using:
            var email   = tokenS.Claims.First(claim => claim.Type == "email").Value;
            var account = _context.Accounts.SingleOrDefault(p => p.Email == email);

            if (account == null)
            {
                return(BadRequest());
            }

            var nameDelete = account.AvatarUrl.Substring(account.AvatarUrl.LastIndexOf("/") + 1);

            if (nameDelete != "default.jpg")
            {
                try
                {
                    System.IO.File.Delete(rootpath + "//Avatars//" + nameDelete);
                }
                catch (Exception)
                {
                    throw;
                }
            }

            string newname = account.Id + "_" + imageModel.Name;

            using (FileStream fs = System.IO.File.Create(rootpath + "\\Avatars\\" + newname))
            {
                fs.Close();
                System.IO.File.WriteAllBytes(rootpath + "\\Avatars\\" + newname, Convert.FromBase64String(imageModel.ImageBase64));
            }
            account.AvatarUrl             = "freelancervn.somee.com/api/images/avatars/" + newname;
            _context.Entry(account).State = EntityState.Modified;
            _context.SaveChanges();
            return(Ok(new { message = "Successful", url = account.AvatarUrl }));
        }
Exemple #11
0
        public async Task <IActionResult> PutBankAccount(int id, BankAccountPostModel
                                                         bankAccountPostModel)
        {
            String jwt = Request.Headers["Authorization"];

            jwt = jwt.Substring(7);
            //Decode jwt and get payload
            var stream    = jwt;
            var handler   = new JwtSecurityTokenHandler();
            var jsonToken = handler.ReadToken(stream);
            var tokenS    = jsonToken as JwtSecurityToken;
            //I can get Claims using:
            var     email   = tokenS.Claims.First(claim => claim.Type == "email").Value;
            Account account = _context.Accounts.Include(p => p.BankAccounts)
                              .SingleOrDefault(p => p.Email == email);

            if (account == null)
            {
                return(BadRequest());
            }
            BankAccount bankAccount = account.BankAccounts.SingleOrDefault(p => p.Id == id);

            bankAccount.BankId                = bankAccountPostModel.BankId;
            bankAccount.OwnerName             = bankAccountPostModel.OwnerName;
            bankAccount.AccountNumber         = bankAccountPostModel.AccountNumber;
            bankAccount.BranchName            = bankAccountPostModel.BranchName;
            _context.Entry(bankAccount).State = EntityState.Modified;
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BankAccountExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(Ok());
        }
Exemple #12
0
        public async Task <IActionResult> PutRating(int id, RatingPost ratingPost)
        {
            Rating rating = _context.Ratings.Find(id);

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

            String jwt = Request.Headers["Authorization"];

            jwt = jwt.Substring(7);
            //Decode jwt and get payload
            var stream    = jwt;
            var handler   = new JwtSecurityTokenHandler();
            var jsonToken = handler.ReadToken(stream);
            var tokenS    = jsonToken as JwtSecurityToken;
            //I can get Claims using:
            var email = tokenS.Claims.First(claim => claim.Type == "email").Value;

            var renter = await _context.Accounts
                         .SingleOrDefaultAsync(p => p.Email == email);

            if (renter == null)
            {
                return(BadRequest());
            }
            var job = renter.JobRenters.SingleOrDefault(p => p.Id == ratingPost.JobID);

            if (job == null)
            {
                return(BadRequest());
            }

            rating.JobId                 = rating.JobId;
            rating.RenterId              = renter.Id;
            rating.FreelancerId          = ratingPost.FreelancerId;
            rating.Star                  = rating.Star;
            rating.Comment               = ratingPost.Comment;
            _context.Entry(rating).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(Ok());
        }
        public async Task <IActionResult> PutCapacityProfile(int id, CProfilePostModel cpEditModel)
        {
            CapacityProfile capacityProfile = _context.CapacityProfiles
                                              .Include(p => p.ProfileServices)
                                              .SingleOrDefault(p => p.Id == id);

            if (capacityProfile == null)
            {
                return(NotFound());
            }
            String jwt = Request.Headers["Authorization"];

            jwt = jwt.Substring(7);
            //Decode jwt and get payload
            var stream    = jwt;
            var handler   = new JwtSecurityTokenHandler();
            var jsonToken = handler.ReadToken(stream);
            var tokenS    = jsonToken as JwtSecurityToken;
            //I can get Claims using:
            var email   = tokenS.Claims.First(claim => claim.Type == "email").Value;
            var account = _context.Accounts.SingleOrDefaultAsync(p => p.Email == email);

            if (account == null || account.Id != capacityProfile.FreelancerId)
            {
                return(BadRequest());
            }
            //create image
            string newname = "";

            if (cpEditModel.ImageBase64 != "")
            {
                string rootpath = _webHostEnvironment.WebRootPath;

                newname = cpEditModel.ImageName + "_" + capacityProfile.Id;

                using (FileStream fs = System.IO.File.Create(rootpath + "\\Images" + newname))
                {
                    fs.Close();
                    System.IO.File.WriteAllBytes(rootpath + "\\Images" + newname, Convert.FromBase64String(cpEditModel.ImageBase64));
                }
                if (capacityProfile.ImageUrl != null)
                {
                    var nameDelete = capacityProfile.ImageUrl
                                     .Substring(capacityProfile.ImageUrl.LastIndexOf("/") + 1);
                    try
                    {
                        System.IO.File.Delete(rootpath + "\\Images\\" + nameDelete);
                    }
                    catch (Exception) {}
                }
            }

            capacityProfile.Name        = cpEditModel.Name;
            capacityProfile.Description = cpEditModel.Description;
            capacityProfile.Urlweb      = cpEditModel.Urlweb;
            capacityProfile.ImageUrl    = newname == ""?capacityProfile.ImageUrl:
                                          "freelancervn.somee.com/api/images/images/" + newname;
            _context.ProfileServices.RemoveRange(capacityProfile.ProfileServices.ToArray());
            await _context.SaveChangesAsync();

            foreach (var item in cpEditModel.Services)
            {
                _context.ProfileServices.Add(new ProfileService
                {
                    Cpid      = id,
                    ServiceId = item.Id,
                });
            }

            _context.Entry(capacityProfile).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CapacityProfileExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok());
        }
        public async Task <IActionResult> PutAccount(int id, AccountEditModel accountEditModel)
        {
            var account = _context.Accounts.Find(id);

            if (account == null)
            {
                return(NotFound());
            }
            String jwt = Request.Headers["Authorization"];

            jwt = jwt.Substring(7);
            //Decode jwt and get payload
            var stream    = jwt;
            var handler   = new JwtSecurityTokenHandler();
            var jsonToken = handler.ReadToken(stream);
            var tokenS    = jsonToken as JwtSecurityToken;
            //I can get Claims using:
            var email = tokenS.Claims.First(claim => claim.Type == "email").Value;

            if (account.Email != email)
            {
                return(BadRequest());
            }

            account.Name        = accountEditModel.Name;
            account.RoleId      = accountEditModel.RoleId;
            account.Phone       = accountEditModel.Phone;
            account.Tile        = accountEditModel.Tile;
            account.Description = accountEditModel.Description;
            account.Website     = accountEditModel.Website;
            account.SpecialtyId = accountEditModel.SpecialtyId;
            account.LevelId     = accountEditModel.LevelId;
            account.ProvinceId  = accountEditModel.ProvinceID;
            var arrSkillsRemove   = _context.FreelancerSkills.Where(p => p.FreelancerId == account.Id).ToArray();
            var arrServicesRemove = _context.FreelancerServices.Where(p => p.FreelancerId == account.Id).ToArray();

            _context.FreelancerServices.RemoveRange(arrServicesRemove);
            _context.FreelancerSkills.RemoveRange(arrSkillsRemove);
            await _context.SaveChangesAsync();

            foreach (var item in accountEditModel.Skills)
            {
                _context.FreelancerSkills.Add(new FreelancerSkill()
                {
                    FreelancerId = account.Id,
                    SkillId      = item.Id
                });
            }

            foreach (var item in accountEditModel.Services)
            {
                _context.FreelancerServices.Add(new FreelancerService()
                {
                    FreelancerId = account.Id,
                    ServiceId    = item.Id
                });
            }
            _context.Entry(account).State = EntityState.Modified;
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AccountExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(Ok());
        }