Exemplo n.º 1
0
 public async Task FaceAuth([FromForm] AddFaceModel model)
 {
     var faceClient = new FaceClient(
         new ApiKeyServiceClientCredentials(SubscriptionKey),
         new System.Net.Http.DelegatingHandler[] { });
     faceClient.Endpoint = FaceEndpoint;
     // await faceClient.PersonGroup.CreateAsync(Group, Group);
     using (var main = new MemoryStream())
     using (var modelMain = model.Main.OpenReadStream())
     using (var modelOne = model.One.OpenReadStream())
     using (var modelTwo = model.Two.OpenReadStream())
     {
         modelMain.CopyTo(main);
         main.Seek(0, 0);
         var person = await faceClient.PersonGroupPerson.CreateAsync(Group, Guid.NewGuid().ToString());
         await faceClient.PersonGroupPerson.AddFaceFromStreamAsync(Group, person.PersonId, model.Main.OpenReadStream());
         await faceClient.PersonGroupPerson.AddFaceFromStreamAsync(Group, person.PersonId, modelOne);
         await faceClient.PersonGroupPerson.AddFaceFromStreamAsync(Group, person.PersonId, modelTwo);
         await faceClient.PersonGroup.TrainAsync(Group);
         var user = AppUser.WithFace(person.PersonId.ToString(), "");
         user.Name = model.Name;
         user.Passport = model.Passport;
         main.Seek(0, 0);
         user.Avatar = main.GetBuffer();
         await _appDb.AddAsync(user);
         await _appDb.SaveChangesAsync();
     }
 }
Exemplo n.º 2
0
        public async Task <IActionResult> AboutUser(string userId, int kursId)
        {
            if (userId != null && kursId != 0)
            {
                var have = await db.UserKurs.FirstOrDefaultAsync(x => x.UserId == userId && x.KursId == kursId);

                if (have != null)
                {
                    db.Remove(have);
                    await db.SaveChangesAsync();
                }
                else
                {
                    UserKurs uk = new UserKurs {
                        UserId = userId, KursId = kursId
                    };

                    await db.AddAsync(uk);

                    await db.SaveChangesAsync();
                }
                AboutUserView auv = new AboutUserView()
                {
                    User     = db.Users.FirstOrDefault(x => x.Id == userId),
                    Kurs     = await db.Kurs.ToListAsync(),
                    UserKurs = await db.UserKurs.Where(x => x.UserId == userId).ToListAsync()
                };
                return(View(auv));
            }

            return(RedirectToAction("UserList"));
        }
Exemplo n.º 3
0
        public async Task <ActionResult <ReservationResponse> > CreateAsync(ReservationRequest item)
        {
            var roomItem = await db.Rooms.FindAsync(item.RoomId);

            if (roomItem == null)
            {
                return(NotFound(new ProblemDetails
                {
                    Title = $"Room id {item.RoomId} not found"
                }));
            }

            var hasOverlapped = db.Reservations.Where(q =>
                                                      q.RoomId == item.RoomId &&
                                                      !q.IsCanceled &&
                                                      q.CheckInDate <= item.CheckInDate &&
                                                      q.CheckOutDate >= item.CheckInDate
                                                      ).Any();

            if (hasOverlapped)
            {
                return(BadRequest(new ProblemDetails
                {
                    Title = $"Reservation Duplicate"
                }));
            }

            var newItem = item.ToModel();
            await db.AddAsync(newItem);

            await db.SaveChangesAsync();


            return(CreatedAtAction(nameof(GetByIdAsync), new { id = item.Id }, ReservationResponse.FromModel(newItem)));
        }