Ejemplo n.º 1
0
        public async Task <IActionResult> JoinFamily(string invitationCode, int Id)
        {
            var family = await _dbRead.GetSingleRecordAsync <Family>(u => u.Id.Equals(Id));

            if (family != null)
            {
                if (family.InvitationCode == invitationCode)
                {
                    var user = await _dbRead.GetSingleRecordAsync <UserProfile>(u =>
                                                                                u.Id.Equals(UserData.UserProfileId));

                    if (user.FamilyId == null)
                    {
                        user.FamilyId = Id;
                        _dbWrite.Update(user);
                        await _dbWrite.SaveChangesAsync();
                    }
                }
                else
                {
                    TempData["notifyUserWarning"] = "There was a problem with your invitation code or family ID";
                }
            }

            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync()

        {
            if (ModelState.IsValid)

            {
                Input.CourseId = _dbReadService.Get <Module>(Input.ModuleId).CourseId;

                Input.Course = null;

                var success = await _dbWriteService.Update(Input);



                if (success)

                {
                    StatusMessage = $"Updated Video: {Input.Title}.";

                    return(RedirectToPage("Index"));
                }
            }



            // If we got this far, something failed, redisplay form

            return(Page());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,NoteId,NoteListItem1,CreatedOn,CreatedBy")] NoteListItem noteListItem)
        {
            if (id != noteListItem.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    noteListItem.CreatedBy = User.Identity.Name;
                    noteListItem.CreatedOn = DateTime.Now;

                    _dbWrite.Update(noteListItem);
                    await _dbWrite.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NoteListItemExists(noteListItem.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                noteId = 0;
                return(RedirectToAction("Index", "NoteListItems", new { Id = noteListItem.NoteId }));
            }
            ViewData["NoteId"] = new SelectList(_context.Note, "Id", "Id", noteListItem.NoteId);
            return(View(noteListItem));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var result = await _dbWriteService.Update(Input);

                    if (result)
                    {
                        //reload original ProductInventory to get navigation properties
                        Input = _dbReadService.Get <ProductInventory>(Input.ProductId, Input.StyleId, Input.LocationId, includeRelatedEntities: true);
                        //Message sent back to Index razor page
                        StatusMessage = $"Updated inventory entry for item # {Input.Product.ItemNumber} of style {Input.Style.Name} at {Input.Location.Name}.";
                        return(RedirectToPage("Index"));
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }
            //something failed, redisplay the form
            return(Page());
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Text,Advanced,DueDate,UserProfileId,ShareToFam,CreatedOn,CreatedBy")] Note note)
        {
            if (id != note.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    note.UserProfileId = UserData.UserProfileId;

                    _dbWrite.Update(note);
                    await _dbWrite.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NoteExists(note.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserProfileId"] = new SelectList(_context.UserProfile, "Id", "UserId", note.UserProfileId);
            return(View(note));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,ContainerSizeTypeName")] ContainerSizeType containerSizeType)
        {
            if (id != containerSizeType.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _dbWriteService.Update(containerSizeType);
                    await _dbWriteService.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    bool result = await ContainerSizeTypeExists(containerSizeType.Id);

                    if (!result)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(containerSizeType));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,UserId,FamilyId,Email,Profile,FirstName,LastName,Picture,PictureContentType,Blurb,CreatedOn,CreatedBy,UpdatedOn,UpdatedBy")] UserProfile userProfile, IFormFile file)
        {
            if (id != userProfile.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (file != null)
                    {
                        // MediaHelper does the work, just send the file over.
                        userProfile.Picture = MediaHelper.ResizeImageFromFile(file);

                        // byte array was returned with 0 length meaning the file is too large, try again!
                        if (userProfile.Picture.Length == 0)
                        {
                            TempData["notifyUserWarning"] = Constants.ImageMediaExceedsSizeLimit;
                            return(RedirectToAction("Edit", "UserProfiles"));
                        }

                        userProfile.PictureContentType = file.ContentType;
                    }
                    else
                    {
                        userProfile.Picture = UserData.ProfileImage;
                    }

                    _dbWrite.Update(userProfile);
                    await _dbWrite.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserProfileExists(userProfile.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                if (userProfile.LastName != null || userProfile.FirstName != null || userProfile.Email != null)
                {
                    UserData.UserProfileComplete = true;
                }
                else
                {
                    TempData["notifyUserWarning"] = "Your profile is not complete!";
                }

                return(RedirectToAction("Details", "UserProfiles", new { Id = id }));
            }
            ViewData["FamilyId"] = new SelectList(_context.Family, "Id", "Id", userProfile.FamilyId);
            return(View(userProfile));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> CreateProduct(int id, [Bind("Id,ProductName,ProductDescription,Upccode,ProductLocation,ProductCost,ProductPrice,SuggestedPrice,PackageSize,PackageType,ContainerSizeTypeId,ContainerTypeId,OrderWeek,CategoryId,CreatedOn,CreatedBy,UpdatedOn,UpdatedBy,UnitsPerCase,SupplierData")] Product product)
        {
            var requestId = id;

            product.Id = 0;

            if (ModelState.IsValid)
            {
                if (User != null)
                {
                    var userFullName = User.Claims.FirstOrDefault(x => x.Type == $"emails").Value;
                    product.CreatedBy = userFullName;
                }

                product.CreatedOn = DateTime.Now;

                _dbWriteService.Add(product);
                await _dbWriteService.SaveChangesAsync();

                _dbReadService.IncludeEntityNavigation <Request>();
                var request = await _dbReadService.GetSingleRecordAsync <Request>(s => s.Id.Equals(requestId));

                request.ProductId = product.Id;
                _dbWriteService.Update(request);
                await _dbWriteService.SaveChangesAsync();

                if (request.StoreId != null)
                {
                    RequestEmail requestEmail = new RequestEmail(_configuration, _dbReadService);
                    requestEmail.SendRequestToStoreManager(request);
                }

                RequestLogHelper logHelper = new RequestLogHelper();
                logHelper.LogRequestChange(request, _context, RequestLogConstants.RequestAddByVendor);
            }

            ViewData["CategoryId"] = new SelectList(_context.Category, "Id", "CategoryName", product.CategoryId);
            ViewData["OrderWeeks"] = new SelectList(new Dictionary <int, int>()
            {
                { 1, 1 }, { 2, 2 }, { 3, 3 }, { 4, 4 }, { 5, 5 }, { 6, 6 }, { 7, 7 }, { 8, 8 }, { 9, 9 }
            }, "Key", "Value", product.OrderWeek);

            return(RedirectToAction("Details", "Requests", new { id = requestId }));
        }
Ejemplo n.º 9
0
        public async Task <bool> UpdateAsync <TSource, TDestination>(TSource item) where TSource : class where TDestination : class
        {
            try
            {
                var entity = _mapper.Map <TDestination>(item);
                _dbWrite.Update(entity);
                return(await _dbWrite.SaveChangesAsync());
            }
            catch { }

            return(false);
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,ProductId,PackageTypeId,StoreId,StorePrice,StoreCost,CreatedOn,CreatedBy,UpdatedOn,UpdatedBy")]
                                               ProductStoreSpecific productStoreSpecific)
        {
            var fullProductStoreSpecific = await _dbReadService.GetSingleRecordAsync <ProductStoreSpecific>(p => p.Id.Equals(id));

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

            if (ModelState.IsValid)
            {
                try
                {
                    if (User != null)
                    {
                        var userFullName = User.Claims.FirstOrDefault(x => x.Type == $"name").Value;
                        productStoreSpecific.UpdatedBy = userFullName;
                    }

                    productStoreSpecific.UpdatedOn = DateTime.Now;

                    if (fullProductStoreSpecific != null)
                    {
                        productStoreSpecific.PackageTypeId = fullProductStoreSpecific.PackageTypeId;
                    }
                    _dbWriteService.Update(productStoreSpecific);
                    await _dbWriteService.SaveChangesAsync();

                    ViewData["PackageTypeId"] = productStoreSpecific.PackageTypeId;

                    return(RedirectToAction("Index", "ProductStoreSpecificPackages", new { id = productStoreSpecific.PackageTypeId }));
                }
                catch (DbUpdateConcurrencyException)
                {
                    bool result = await ProductStoreSpecificExists(productStoreSpecific.Id);

                    if (!result)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(View(productStoreSpecific));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            var success = await _dbWriteService.Update(Input);

            if (!success)
            {
                return(Page());
            }
            StatusMessage = $"Updated Band: {Input.Name}.";
            return(RedirectToPage("Index"));
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            Input.Album = null;
            var success = await _dbWriteService.Update(Input);

            if (!success)
            {
                return(Page());
            }
            StatusMessage = $"Video {Input.Title} was updated.";
            return(RedirectToPage("Index"));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                var success = await _dbWriteService.Update(Input);

                if (success)
                {
                    StatusMessage = $"Updated Module: {Input.Title}.";
                    return(RedirectToPage("Index"));
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                var result = await _dbWriteService.Update(Input);

                if (result)
                {
                    //Message sent back to Index razor page
                    StatusMessage = $"Updated Style: {Input.Name}";
                    return(RedirectToPage("Index"));
                }
            }
            //something failed, redisplay the form
            return(Page());
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            var success = await _dbWriteService.Update(Input.UserGenre, Input.UpdatedUserGenre);

            if (!success)
            {
                return(Page());
            }
            var updatedCourse = _dbReadService.Get <Genre>(Input.UpdatedUserGenre.GenreId);

            StatusMessage =
                $"The {Input.GenreTitle}/{Input.Email} combination was changed to: {updatedCourse.Title}/{Input.Email}.";
            return(RedirectToPage("Index"));
        }
Ejemplo n.º 16
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                var success = await _dbWriteService.Update(Input.UserCourse, Input.UpdatedUserCourse);

                if (success)
                {
                    var updatedCourse = _dbReadService.Get <Course>(Input.UpdatedUserCourse.CourseId);
                    StatusMessage = $"The [{Input.CourseTitle} | {Input.Email}] combination was changed to [{updatedCourse.Title} | {Input.Email}].";
                    return(RedirectToPage("Index"));
                }
            }

            // If we got this far, something failed, redisplay form
            ViewData["Courses"] = _dbReadService.GetSelectList <Course>("Id", "Title");
            return(Page());
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,RequestDescription,RequestTypeId,StatusTypeId,UserId,ProductId,SupplierId,StoreId,CreatedOn,CreatedBy,UpdatedOn,UpdatedBy")] Request request)
        {
            if (id != request.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (User != null)
                    {
                        var userFullName = User.Claims.FirstOrDefault(x => x.Type == $"emails").Value;
                        request.UpdatedBy = userFullName;
                    }

                    request.UpdatedOn  = DateTime.Now;
                    request.SupplierId = RequestDto.SupplierId;
                    request.UserId     = request.UserId = UserDto.UserId;

                    _dbWriteService.Update(request);

                    await _dbWriteService.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    bool result = await RequestExists(request.Id);

                    if (!result)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }

            return(View(request));
        }
Ejemplo n.º 18
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,ProductId,PackageTypeId,StoreId,StorePrice,StoreCost,CreatedOn,CreatedBy,UpdatedOn,UpdatedBy")] ProductStoreSpecific productStoreSpecific)
        {
            if (id != productStoreSpecific.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (User != null)
                    {
                        var userFullName = User.Claims.FirstOrDefault(x => x.Type == $"name").Value;
                        productStoreSpecific.UpdatedBy = userFullName;
                    }

                    productStoreSpecific.UpdatedOn = DateTime.Now;
                    _dbWriteService.Update(productStoreSpecific);
                    await _dbWriteService.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    bool result = await ProductStoreSpecificExists(productStoreSpecific.Id);

                    if (!result)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index", "ProductStoreSpecificProducts", new { id = productStoreSpecific.ProductId }));
            }

            ViewData["ProductId"] = new SelectList(_context.Product, "Id", "ProductName", productStoreSpecific.ProductId);

            return(View(productStoreSpecific));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Quantity,Unit,AlternateProductName,AlternateProductUpccode,SupplierData,SupplierId,AlternateProductPrice,AlternateProductCost,AlternateSuggestedPrice,ProductId,CreatedOn,CreatedBy,UpdatedOn,UpdatedBy")] ProductPackageType productPackageType)
        {
            if (id != productPackageType.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (User != null)
                    {
                        var userFullName = User.Claims.FirstOrDefault(x => x.Type == $"name").Value;
                        productPackageType.UpdatedBy = userFullName;
                    }

                    productPackageType.UpdatedOn = DateTime.Now;

                    _dbWriteService.Update(productPackageType);
                    await _dbWriteService.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    bool result = await ProductPackageTypeExists(productPackageType.Id);

                    if (!result)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            ViewData["ProductId"]  = new SelectList(_context.Product, "Id", "ProductName", productPackageType.ProductId);
            ViewData["SupplierId"] = new SelectList(_context.Supplier, "Id", "SupplierName", productPackageType.SupplierId);

            return(RedirectToAction("Index", "ProductPackageTypes", new { id = productPackageType.ProductId }));
        }
Ejemplo n.º 20
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,SupplierName,SupplierEmail,CreatedOn,CreatedBy,UpdatedOn,UpdatedBy")] Supplier supplier)
        {
            if (id != supplier.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (User != null)
                    {
                        var userFullName = User.Claims.FirstOrDefault(x => x.Type == $"name").Value;
                        supplier.UpdatedBy = userFullName;
                    }

                    supplier.UpdatedOn = DateTime.Now;

                    _dbWriteService.Update(supplier);

                    await _dbWriteService.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    bool result = await SupplierExists(supplier.Id);

                    if (!result)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(supplier));
        }
Ejemplo n.º 21
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,NoteText,SendEmailRequestor,SendEmailSupplier,RequestId,CreatedOn,CreatedBy,UpdatedOn,UpdatedBy")] Note note)
        {
            if (id != note.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (User != null)
                    {
                        var userFullName = User.Claims.FirstOrDefault(x => x.Type == $"emails").Value;
                        note.UpdatedBy = userFullName;
                    }

                    note.UpdatedOn = DateTime.Now;

                    _dbWriteService.Update(note);
                    await _dbWriteService.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    bool result = await NoteExists(note.Id);

                    if (!result)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            ViewData["RequestId"] = new SelectList(_context.Request, "Id", "RequestDescription", note.RequestId);
            return(RedirectToAction("Index", "Notes", new { id = note.RequestId }));
        }
Ejemplo n.º 22
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,SupplierId,FirstName,LastName,EmailAddress,AuthId,CreatedOn,CreatedBy,UpdatedOn,UpdatedBy")] User user)
        {
            if (id != user.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (User != null)
                    {
                        var userFullName = User.Claims.FirstOrDefault(x => x.Type == $"name").Value;
                        user.UpdatedBy = userFullName;
                    }

                    user.UpdatedOn = DateTime.Now;

                    _dbWriteService.Update(user);

                    await _dbWriteService.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["SupplierId"] = new SelectList(_context.Supplier, "Id", "SupplierName", user.SupplierId);
            return(View(user));
        }
Ejemplo n.º 23
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var result = await _dbWriteService.Update(Input);

                    if (result)
                    {
                        //Message sent back to Index razor page
                        StatusMessage = $"Updated Product: {Input.ItemNumber}";
                        return(RedirectToPage("Index"));
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }
            //something failed, redisplay the form
            return(Page());
        }
Ejemplo n.º 24
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,RequestDescription,RequestTypeId,StatusTypeId,UserId,ProductId,SupplierId,StoreId,CreatedOn,CreatedBy,UpdatedOn,UpdatedBy")] Request request)
        {
            if (id != request.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (User != null)
                    {
                        string claimTypeEmailAddress = $"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name";
                        var    userFullName          = User.Claims.FirstOrDefault(x => x.Type == $"name").Value;
                        request.UserId    = User.Claims.FirstOrDefault(x => x.Type == claimTypeEmailAddress).Value;
                        request.UpdatedBy = userFullName;
                    }

                    request.UpdatedOn = DateTime.Now;

                    request.ProductId = _dbReadService.GetSingleRecordAsync <Request>(p => p.Id.Equals(request.Id)).Result.ProductId;

                    _dbWriteService.Update(request);
                    await _dbWriteService.SaveChangesAsync();

                    var status = await _dbReadService.GetSingleRecordAsync <StatusType>(s => s.Id.Equals(request.StatusTypeId));

                    if (request.StatusTypeId != RequestDto.StatusId)
                    {
                        switch (status.StatusTypeName)
                        {
                        case "New Request":
                            break;

                        case "Approved":
                            RequestLogHelper logHelperApproved = new RequestLogHelper();
                            logHelperApproved.LogRequestChange(request, _context, RequestLogConstants.RequestApproved);

                            RequestEmail requestEmailManager = new RequestEmail(_configuration, _dbReadService);
                            requestEmailManager.SendApprovedRequestEmailToHeadQuarters(request);
                            break;

                        case "Denied":
                            RequestLogHelper logHelperDenied = new RequestLogHelper();
                            logHelperDenied.LogRequestChange(request, _context, RequestLogConstants.RequestDenied);

                            RequestEmail requestEmailOriginator = new RequestEmail(_configuration, _dbReadService);
                            requestEmailOriginator.SendDeniedRequestEmailToOriginatingUser(request);

                            break;

                        case "Complete":
                            RequestLogHelper logHelperComplete = new RequestLogHelper();
                            logHelperComplete.LogRequestChange(request, _context, RequestLogConstants.RequestComplete);

                            RequestEmail requestEmailCompletedStatus = new RequestEmail(_configuration, _dbReadService);
                            requestEmailCompletedStatus.SendRequestCompletedToGroup(request);
                            break;
                        }
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    bool result = await RequestExists(request.Id);

                    if (!result)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }

            RequestDto.StatusId = null;
            return(View(request));
        }