Beispiel #1
0
        public IActionResult Put(int id, ParkingProfileViewModel model)
        {
            if (id == 0 && model == null)
            {
                return(null);
            }

            var parking = _dbContext.parkings
                          .FirstOrDefault(p => p.ParkingId == id);
            var facilities = _dbContext.ParkingFacilities
                             .FirstOrDefault(p => p.Parking.ParkingId == parking.ParkingId);

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



            parking.Name        = model.Name;
            parking.Description = model.Description;
            parking.City        = model.City;
            parking.Address     = model.Address;

            var result = _dbContext.Update(parking);

            if (_dbContext.SaveChanges() > 0)
            {
                if (facilities == null)
                {
                    var facility = new ParkingFacilities()
                    {
                        Parking        = parking,
                        GuestRoom      = model.GuestRoom,
                        OnlinePayment  = model.OnlinePayment,
                        ServiceStation = model.ServiceStation
                    };

                    _dbContext.Add(facilities);
                    _dbContext.SaveChanges();
                }
                else
                {
                    facilities.ServiceStation = model.ServiceStation;
                    facilities.OnlinePayment  = model.OnlinePayment;
                    facilities.GuestRoom      = model.GuestRoom;
                    _dbContext.Update(facilities);
                    _dbContext.SaveChanges();
                }
            }


            return(Ok());
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,CurrentDate,CurrentText,Name,Email")] Guest guest)
        {
            if (id != guest.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(guest);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GuestExists(guest.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(guest));
        }
Beispiel #3
0
        /// <summary>
        /// Resets the password for a username. A new password is randomly generated and assigned.
        /// </summary>
        /// <param name="username">Username</param>
        /// <param name="apiKey">API Key</param>
        /// <returns></returns>
        public async Task <string> ResetPasswordAsync(string username, string apiKey)
        {
            if (apiKey != JwtOptions.ApiKey && IsInProduction)
            {
                throw new ArgumentException("Invalid API Key.");
            }

            Users user = await AuthDbContext.Users
                         .FirstOrDefaultAsync(usr => usr.Username == username);

            if (user == null)
            {
                throw new ArgumentException("Invalid username.");
            }

            var newPassword = Core.Helpers.StringHelpers.GetRandomPassword(8);

            DateTime now = DateTime.Now;

            user.PasswordCreatedOn = now;
            user.PasswordExpiresOn = now.AddMonths(6);
            user.PasswordHash      = Crypto.HashPassword(newPassword);

            AuthDbContext.Update(user);
            await AuthDbContext.SaveChangesAsync();

            return(newPassword);
        }
        public async Task <IActionResult> Edit(int id, [Bind("id,name,make,year,price,os")] Phone phone)
        {
            if (id != phone.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(phone);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PhoneExists(phone.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(phone));
        }
Beispiel #5
0
        public async Task <IActionResult> Edit(int id, [Bind("chargerId,chargerName,chargerPort,chargerPrice")] Charger charger)
        {
            if (id != charger.chargerId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(charger);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ChargerExists(charger.chargerId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(charger));
        }
        public async Task <IActionResult> Edit(int id, [Bind("id,Subject,Description,StartTime,EndTime,AppUserId,GroupId")] Exam exam)
        {
            if (id != exam.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(exam);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ExamExists(exam.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AppUserId"] = new SelectList(_context.AppUsers, "Id", "Id", exam.AppUserId);
            ViewData["GroupId"]   = new SelectList(_context.Groups, "id", "AppUserId", exam.GroupId);
            return(View(exam));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,adi,soyadi,adres,Ulkesi")] Ogrenci ogrenci)
        {
            if (id != ogrenci.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(ogrenci);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OgrenciExists(ogrenci.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(ogrenci));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ProductId,ProductNumber,ProductName,ProductDescription,ProductCategory,Price,Date")] ProductsModel productModel)
        {
            if (id != productModel.ProductId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(productModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductModelExists(productModel.ProductId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(productModel));
        }
        public async Task <IActionResult> Edit(int id, [Bind("SaleId,SaleValue,AddedDate,FromDate,ToDate")] Sale sale, string product)
        {
            if (id != sale.SaleId)
            {
                return(NotFound());
            }

            List <SelectListItem> products = new List <SelectListItem>();

            foreach (var productValue in _context.Products)
            {
                products.Add(new SelectListItem()
                {
                    Value = productValue.ProductName, Text = productValue.ProductName
                });
            }
            ViewBag.Products = products;

            if (sale.SaleValue > 1 || sale.SaleValue < 0)
            {
                StatusMessage = "Error. Invalid range for sale value.";
                return(RedirectToAction());
            }

            Product findProduct = _context.Products.Where(value => value.ProductName == product).First();

            if (findProduct != null)
            {
                sale.Product = findProduct;
            }
            else
            {
                StatusMessage = "Not all properties choosen";
                return(RedirectToAction());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(sale);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SaleExists(sale.SaleId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                StatusMessage = "Sale has been updated";
                return(RedirectToAction(nameof(Index)));
            }
            StatusMessage = "Error. Invalid form.";
            return(View(sale));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,PostText,PostImage,PublicDate,UserId")] Post post)
        {
            if (id != post.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(post);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PostExists(post.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", post.UserId);
            return(View(post));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,DbConnectionString")] Branch branch)
        {
            if (id != branch.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(branch);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BranchExists(branch.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(branch));
        }
Beispiel #12
0
        public async Task <IActionResult> MarkAsReceived(int id, string donatorTeamId)
        {
            var donation = _context.Donations.Where(d => d.Id == id && d.DonatorTeamId == donatorTeamId).FirstOrDefault();
            var donatorTeamIdFromDonation = donation.DonatorTeamId;

            donation.Status = "Received";

            var part = _context.Parts.Where(p => p.Id == donation.PartId).FirstOrDefault();

            part.Status = "NotAvailable";

            var user = _authDbContext.Users.Where(u => u.Id == donatorTeamId).FirstOrDefault();

            user.NumberOfSuccessDonations = user.NumberOfSuccessDonations + 1;

            var notification = _context.Notifications.Where(n => n.Id == 6).FirstOrDefault();

            UsersNotifications userNotification = new UsersNotifications
            {
                NotificationId = notification.Id,
                ReceptorTeamId = donatorTeamIdFromDonation,
                DeliverTeamId  = donation.InterestedTeamId
            };

            _context.Update(donation);
            _context.Update(part);
            _authDbContext.Update(user);

            await _context.SaveChangesAsync();

            await _authDbContext.SaveChangesAsync();

            return(RedirectToAction("InterestedTeamProfile", "Profile", new { interestedTeamId = donatorTeamIdFromDonation }));
        }
        public IActionResult Post([FromForm] IFormFile file, int id)
        {
            var park = _context.parkings.FirstOrDefault(p => p.ParkingId == id);



            if (park == null)
            {
                return(NotFound());
            }
            using (var memoryStream = new MemoryStream())
            {
                file.CopyToAsync(memoryStream);
                park.ParkImage = memoryStream.ToArray();
            }

            var result = _context.Update(park);

            if (_context.SaveChanges() == 0)
            {
                return(BadRequest());
            }



            return(Ok());
        }
        public async Task <IActionResult> Edit(int id, [Bind("caseId,caseName,casePrice,caseColor")] Case cases)
        {
            if (id != cases.caseId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(cases);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CaseExists(cases.caseId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            CaseListViewModel casesListViewModel = new CaseListViewModel();

            casesListViewModel.Cases = _caseRepository.List();
            return(View(casesListViewModel));
        }
Beispiel #15
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,CourseId,Description,StudentId,TeacherId,Grade")] Assignement assignement)
        {
            string student = assignement.StudentId;

            if (id != assignement.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    assignement.StudentId = student;
                    _context.Update(assignement);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AssignementExists(assignement.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Edit(int id, [Bind("id,question,option1,option2,option3,option4,ans,ExamId")] Questions questions)
        {
            if (id != questions.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(questions);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!QuestionsExists(questions.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ExamId"] = new SelectList(_context.Exams, "id", "AppUserId", questions.ExamId);
            return(View(questions));
        }
Beispiel #17
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,MessageText,DateOfMessage,UserSenderId,UserReceiverId")] Message message)
        {
            if (id != message.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(message);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MessageExists(message.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserReceiverId"] = new SelectList(_context.Users, "Id", "Id", message.UserReceiverId);
            return(View(message));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id, UserId, Amount,Semester,Paid")] Payment payment)
        {
            if (id != payment.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(payment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PaymentExists(payment.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(payment));
        }
Beispiel #19
0
        public async Task <IActionResult> Edit(int id, [Bind("VendorNumber,VendorName,VendorAddress,Amount,Date")] VendorTransactionModel vendorTransactionModel)
        {
            if (id != vendorTransactionModel.TransactionId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(vendorTransactionModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VendorTransactionModelExists(vendorTransactionModel.TransactionId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(vendorTransactionModel));
        }
Beispiel #20
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,CourseId,CreatorId,Description,UsersId,Start,End")] Exam exam)
        {
            if (id != exam.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(exam);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ExamExists(exam.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(RedirectToAction(nameof(Index)));
        }
Beispiel #21
0
        public async Task <IActionResult> PutSlot(int slotId, SlotCreateViewModel model)
        {
            if (slotId == 0)
            {
                return(null);
            }

            var sLot = _context.slots.FirstOrDefault(p => p.SlotId == slotId);

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

            sLot.No = model.SlotNo;

            _context.Update(sLot);

            if (_context.SaveChanges() == 0)
            {
                return(BadRequest());
            }

            return(Ok());
        }
Beispiel #22
0
        public async Task <IActionResult> UpdateFullName([FromBody] UpdateFullNameViewModel model)
        {
            var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var user   = await dbContext.Users.FindAsync(userId);

            if (user == null)
            {
                return(Unauthorized());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            user.FullName = model.FullName;
            dbContext.Update(user);
            await dbContext.SaveChangesAsync();

            await bus.Publish(new UserChangedFullNameEvent(new Guid(user.Id), user.FullName));

            return(Json(new UserViewModel
            {
                Username = user.UserName, Fullname = user.FullName, Token = GetToken(user.Id, user.FullName)
            }));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,FriendSenderId,FriendReceiverId")] Friend friend)
        {
            if (id != friend.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(friend);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FriendExists(friend.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FriendSenderId"] = new SelectList(_context.Users, "Id", "Id", friend.FriendSenderId);
            return(View(friend));
        }
        public async Task <IActionResult> Edit(long id, [Bind("OrderId,Addres,City,State,Country,ZipCode,AmountPaid,PaymentType,FormedDate")] Order order, string customer)
        {
            if (id != order.OrderId)
            {
                return(NotFound());
            }

            List <SelectListItem> customers = new List <SelectListItem>();

            foreach (var value in _context.Users)
            {
                customers.Add(new SelectListItem()
                {
                    Value = value.UserName, Text = value.UserName
                });
            }
            ViewBag.Customer = customers;

            ApplicationUser temporalUser = _context.Users.Where(value => value.UserName == customer).First();

            if (temporalUser != null)
            {
                order.Customer = temporalUser;
            }
            else
            {
                StatusMessage = "Not all properties choosen";
                return(RedirectToAction());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(order);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OrderExists(order.OrderId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                StatusMessage = "Order has been updated";
                return(RedirectToAction(nameof(Index)));
            }
            StatusMessage = "Error. Invalid form.";
            return(View(order));
        }
Beispiel #25
0
        public IActionResult GetUnreservedSlot(int id)
        {
            ReservationHistoryViewModel model = new ReservationHistoryViewModel();

            if (id == 0)
            {
            }

            var slotreservation = _context.slotReservations.Include(p => p.slot).Include(p => p.slot.Parking)
                                  .FirstOrDefault(p => p.SlotReservationId == id && p.slot.Reserved == true);

            if (slotreservation != null)
            {
                slotreservation.ReservationEndTime = DateTime.Now;

                _context.Update(slotreservation);
                _context.SaveChanges();
            }



            var slot = _context.slots.FirstOrDefault(p => p.SlotId == slotreservation.slot.SlotId);

            if (slot != null)
            {
                slot.Reserved = false;
                _context.Update(slot);
                _context.SaveChanges();
            }


            model.Id              = slotreservation.SlotReservationId;
            model.No              = slotreservation.slot.SlotId;
            model.Parking         = slotreservation.slot.Parking.Name;
            model.ReservationTime = slotreservation.ReservationTime.ToString();
            model.EndTime         = slotreservation.ReservationEndTime.ToString();
            model.City            = slotreservation.slot.Parking.City;


            return(new OkObjectResult(model));
        }
Beispiel #26
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,ClinicName,ClinicDesc,ContactNum,ContactEmail,Status,UserID")] Clinic clinic)
        {
            if (ModelState.IsValid)
            {
                CloudTable         table        = TableStorage("AppointmentTable");
                List <Appointment> appointments = Common.GetAppointmentsList(table);

                foreach (var item in appointments)
                {
                    if (item.PartitionKey.Equals(clinic.Id.ToString()))
                    {
                        await EditTable(item.PartitionKey, item.RowKey, null, clinic.ClinicName);
                    }
                }
                _context.Update(clinic);
                TempData["message"] = "Your clinic details has been updated.";
                await _context.SaveChangesAsync();

                return(RedirectToAction("ManageClinic", new { uID = clinic.UserID }));
            }
            return(View(clinic));
        }
        public async Task <ActionResult> Edit(UserTask newTask)
        {
            if (ModelState.IsValid)
            {
                context.Update(newTask);
                await context.SaveChangesAsync();

                TempData["Success"] = "Успешна промяна на задача";

                return(RedirectToAction("Index"));
            }

            return(View(newTask));
        }
 public bool Update(Category category)
 {
     try
     {
         _context.Update(category);
         _context.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         _logger.LogInformation(e.Message);
         return(false);
     }
 }
        public async Task <IActionResult> Edit(string id, ApplicationUser student)
        {
            var currentAcc = await userManager.FindByIdAsync(id);

            if (ModelState.IsValid)
            {
                currentAcc.Name        = student.Name;
                currentAcc.HomeAddress = student.HomeAddress;

                authDbContext.Update(currentAcc);
                await authDbContext.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(student));
        }
        public async Task <bool> UpdateGroup(Group group)
        {
            try
            {
                _context.Update(group);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GroupExists(group.id))
                {
                    return(false);
                }
                else
                {
                    throw;
                }
            }
        }