示例#1
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());
        }
示例#2
0
        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());
        }
示例#3
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());
        }
示例#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());
        }
示例#5
0
        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());
        }
示例#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());
        }
示例#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());
        }
示例#8
0
        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());
        }
示例#9
0
        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());
        }
示例#10
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());
        }
示例#11
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 <ActionResult <Announcement> > PostAnnouncement(AnnouncementPostModel announcementPostModel)
        {
            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 &&
                                                            p.RoleId == 1);

            if (account == null)
            {
                return(BadRequest());
            }
            Announcement announcement = new Announcement()
            {
                Title  = announcementPostModel.Title,
                Detail = announcementPostModel.Detail,
            };

            _context.Announcements.Add(announcement);
            await _context.SaveChangesAsync();

            foreach (var AccountID in announcementPostModel.AccountIDs)
            {
                _context.AnnouncementAccounts.Add(new AnnouncementAccount()
                {
                    AccountId      = AccountID,
                    AnnouncementId = announcement.Id
                });
            }
            await _context.SaveChangesAsync();

            return(Ok());
        }
示例#13
0
        public async Task <ActionResult <MessageModel> > PostMessage(MessageModel messagePost)
        {
            Message message = new Message()
            {
                JobId     = messagePost.JobId,
                ReceiveId = messagePost.ReceiveId,
                SenderId  = messagePost.SenderId,
                Message1  = messagePost.Message1,
                Status    = "unseen"
            };

            _context.Messages.Add(message);
            await _context.SaveChangesAsync();

            return(Ok());
        }
        public async Task <ActionResult <OfferHistory> > PostOfferHistory([FromBody] OfferHistoryPost offerHistoryPost)
        {
            if (_context.Jobs.Find(offerHistoryPost.JobId) == null)
            {
                return(BadRequest());
            }
            var freelancer = _context.Accounts.Find(offerHistoryPost.FreelancerId);

            if (freelancer == null)
            {
                return(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;

            if (email != freelancer.Email || freelancer.IsAccuracy == false)
            {
                return(BadRequest());
            }
            if (_context.OfferHistories
                .Where(p => p.FreelancerId == freelancer.Id && offerHistoryPost.JobId == p.JobId).Count() >= 3)
            {
                return(Ok("Oops... You have only three times to offer this job."));
            }
            var offerHistory = new OfferHistory()
            {
                JobId        = offerHistoryPost.JobId,
                FreelancerId = offerHistoryPost.FreelancerId,
                Description  = offerHistoryPost.Description,
                ExpectedDay  = offerHistoryPost.ExpectedDay,
                OfferPrice   = offerHistoryPost.OfferPrice,
                TodoList     = offerHistoryPost.TodoList,
            };

            _context.OfferHistories.Add(offerHistory);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (OfferHistoryExists(offerHistory.JobId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }
            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());
        }
示例#16
0
        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());
        }