Example #1
0
        public async Task <IActionResult> CreateDemandAsync([FromBody] DemandDto demandDto)
        {
            try
            {
                var currentUser = await userManager.GetUserAsync(HttpContext.User);

                var userAccountId = GetUserAccountId();

                var roles = await userManager.GetRolesAsync(currentUser);



                demandDto.CreatedUser          = currentUser.FirstName + " " + currentUser.LastName;
                demandDto.ModifiedUser         = currentUser.FirstName + " " + currentUser.LastName;
                demandDto.CreateDate           = DateTime.Now;
                demandDto.ModifyDate           = DateTime.Now;
                demandDto.CompanyUserAccountId = userAccountId;

                if (roles.Contains("Company Admin") || roles.Contains("Company User"))
                {
                    var companyId = companyUserService.GetCompanyUserbyUserAccountId(userAccountId).CompanyId;
                    demandDto.CompanyId = companyId;
                }

                var result = demandService.Create(demandDto);
                return(Ok());
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #2
0
        public int Create(DemandDto demandDto)
        {
            var demand = mapper.Map <Demand>(demandDto);

            demandRepository.Insert(demand);
            unitOfWork.SaveChanges();

            return(demand.Id);
        }
Example #3
0
        public async Task <ActionResult> Edit([FromBody] DemandDto demandDto)
        {
            try
            {
                var currentUser = await userManager.GetUserAsync(HttpContext.User);

                demandDto.ModifiedUser = currentUser.FirstName + " " + currentUser.LastName;
                demandService.Update(demandDto);

                return(View());
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Example #4
0
        public void SetDemandAsCompleted(DemandDto demandDto)
        {
            var demand = demandRepository.Find(demandDto.Id);

            if (demand == null)
            {
                throw new KeyNotFoundException();
            }

            demand.IsCompleted = demandDto.IsCompleted;
            demand.ApplicationUserAccountId = demandDto.ApplicationUserAccountId;
            demand.ModifiedUser             = demandDto.ModifiedUser;
            demand.ModifyDate = DateTime.Now;

            demandRepository.Update(demand);
            unitOfWork.SaveChanges();
        }
Example #5
0
        public void Update(DemandDto demandDto)
        {
            var demand = demandRepository.Find(demandDto.Id);

            if (demand == null)
            {
                throw new KeyNotFoundException();
            }

            demand.Text             = demandDto.Text;
            demand.OrderOfUrgencyId = demandDto.OrderOfUrgencyId;
            demand.ModifiedUser     = demandDto.ModifiedUser;
            demand.ModifyDate       = DateTime.Now;

            demandRepository.Update(demand);
            unitOfWork.SaveChanges();
        }
Example #6
0
        public async Task <ActionResult> SetDemandAsCompleted([FromBody] DemandDto demandDto)
        {
            try
            {
                var currentUser = await userManager.GetUserAsync(HttpContext.User);

                var userId = applicationUserService.GetUserDto(currentUser.AccountId).AccountId;
                demandDto.ApplicationUserAccountId = userId;
                demandDto.ModifiedUser             = currentUser.FirstName + " " + currentUser.LastName;
                demandService.SetDemandAsCompleted(demandDto);

                return(Ok());
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Example #7
0
        public void UpdateForDeletedUser(DemandDto demandDto)
        {
            var demand = demandRepository.Find(demandDto.Id);

            if (demand == null)
            {
                throw new KeyNotFoundException();
            }

            demand.ApplicationUserAccountId = null;
            demand.IsAccepted   = false;
            demand.IsDissolved  = false;
            demand.ModifiedUser = demandDto.ModifiedUser;
            demand.ModifyDate   = DateTime.Now;

            demandRepository.Update(demand);
            unitOfWork.SaveChanges();
        }
        public async Task <IActionResult> Put(string id, [FromBody] DemandDto dto)
        {
            ApiResult apiResult = new ApiResult();
            var       source    = await this.demandService.QueryByIDAsync(dto.Id);

            var copy = source.Clone();

            //把view的数据复制到copy对象
            copy = this.mapper.Map(dto, copy);
            // dto.AssignValuesToEntity(copy);
            //检查新旧对象的差异
            var exp1 = source.UpdateExpression(copy);

            var b = await demandService.UpdateAsync(source, exp1);

            if (!b)
            {
                apiResult.error_code = 50001;
            }
            return(Ok(apiResult));
        }
Example #9
0
        public async Task <QueryResults <ContactDto> > AcceptOrDenyContact(Guid me, Guid demandId, DemandDto demand)
        {
            var contact = await db
                          .Contacts
                          .Include(c => c.MyContact)
                          .GetByIdAsync(demandId) ?? throw new NotFoundApiException();

            if (!contact.Me.Equals(me) || contact.Status != Status.Pending)
            {
                throw new UnauthorizeApiException();
            }

            contact.Status = demand.Status;
            await db.SaveChangesAsync();

            return(new QueryResults <ContactDto>
            {
                Data = contact.ConvertToDto()
            });
        }
Example #10
0
        public async Task <QueryResults <ContactDto> > Contact(Guid me, Guid contactId, DemandDto demand)
        {
            _ = await db.Users.GetByIdAsync(me) ?? throw new NotFoundApiException();

            var contact = await db.Users.GetByIdAsync(contactId) ?? throw new NotFoundApiException();

            var newContact = new Contact
            {
                Me           = me,
                MyContact    = contact,
                FirstMessage = demand.FirstMessage,
                Status       = Status.Pending
            };

            db.Contacts.Add(newContact);
            await db.SaveChangesAsync();

            return(new QueryResults <ContactDto>
            {
                Data = newContact.ConvertToDto()
            });
        }
Example #11
0
 public async Task <IActionResult> AcceptOrDenyContact([FromRoute(Name = "id")] Guid demandId, [FromBody] DemandDto demand)
 {
     try
     {
         var myId = ExtractIdFromToken(Request.Headers[HttpRequestHeader.Authorization.ToString()]);
         return(Ok(await service.AcceptOrDenyContact(myId, demandId, demand)));
     }
     catch (HttpResponseException)
     {
         throw;
     }
     catch (Exception)
     {
         throw new BadRequestApiException();
     }
 }
Example #12
0
        public async Task <IActionResult> Contact([FromRoute(Name = "id")] Guid contactId, [FromBody] DemandDto demand)
        {
            try
            {
                var myId   = ExtractIdFromToken(Request.Headers[HttpRequestHeader.Authorization.ToString()]);
                var result = await service.Contact(myId, contactId, demand);

                return(Created($"/api/contacts/{result.Data.Id}", result));
            }
            catch (HttpResponseException)
            {
                throw;
            }
            catch (Exception)
            {
                throw new BadRequestApiException();
            }
        }