示例#1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var result = await _dbWriteService.Add(Input);

                    if (result)
                    {
                        //Message sent back to Index razor page
                        StatusMessage = $"Created a new product: {Input.ItemNumber}";
                        return(RedirectToPage("Index"));
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }
            //something failed, redisplay the form
            //reload category drop down
            ViewData["Categories"] = _dbReadService.GetSelectList <Category>("CategoryId", "Name");
            return(Page());
        }
示例#2
0
        public async Task <IActionResult> Create(int id, bool multiple, [Bind("Id,Quantity,Unit,AlternateProductName,AlternateProductUpccode,SupplierData,SupplierId,AlternateProductPrice,AlternateProductCost,AlternateSuggestedPrice,ProductId,CreatedOn,CreatedBy,UpdatedOn,UpdatedBy")] ProductPackageType productPackageType)
        {
            productPackageType.Id = 0;
            if (ModelState.IsValid)
            {
                if (User != null)
                {
                    var userFullName = User.Claims.FirstOrDefault(x => x.Type == $"emails").Value;
                    productPackageType.CreatedBy = userFullName;
                }

                productPackageType.SupplierId = RequestDto.SupplierId;
                productPackageType.CreatedOn  = DateTime.Now;

                productPackageType.ProductId = id;
                _dbWriteService.Add(productPackageType);

                await _dbWriteService.SaveChangesAsync();
            }

            ViewData["ProductId"]  = new SelectList(_context.Product, "Id", "ProductName", productPackageType.ProductId);
            ViewData["SupplierId"] = new SelectList(_context.Supplier, "Id", "SupplierName", productPackageType.SupplierId);

            if (multiple == true)
            {
                TempData["notifyUserSuccess"] = "Alternate Package Saved.";
                return(RedirectToAction("Create", "ProductPackageTypes", new { id = productPackageType.ProductId }));
            }

            return(RedirectToAction("Index", "ProductPackageTypes", new { id = productPackageType.ProductId }));
        }
        public async Task <IActionResult> CreateRequest([Bind("Id,RequestDescription,RequestTypeId,StatusTypeId,UserId,SupplierId,StoreId,CreatedOn,CreatedBy,UpdatedOn,UpdatedBy")] Request request)
        {
            if (ModelState.IsValid)
            {
                if (User != null)
                {
                    var userFullName = User.Claims.FirstOrDefault(x => x.Type == $"emails").Value;
                    request.CreatedBy = userFullName;
                }

                request.CreatedOn = DateTime.Now;
                request.UserId    = UserDto.UserId;

                var status = await _dbReadService.GetSingleRecordAsync <StatusType>(s => s.StatusTypeName.Equals("New Request"));

                request.StatusTypeId = status.Id;
                request.SupplierId   = RequestDto.SupplierId;

                _dbWriteService.Add(request);
                await _dbWriteService.SaveChangesAsync();
            }

            ViewData["RequestTypeId"] = new SelectList(_context.RequestType, "Id", "RequestTypeName", request.RequestTypeId);
            ViewData["StatusTypeId"]  = new SelectList(_context.StatusType, "Id", "StatusTypeName", request.StatusTypeId).SelectedValue;

            RequestDto.RequestId = request.Id;

            return(RedirectToAction("CreateProduct", "Products", new { id = request.Id }));
        }
示例#4
0
        public async Task <IActionResult> Create(int?id, [Bind("Id,ProductId,PackageTypeId,StoreId,StorePrice,StoreCost,CreatedOn,CreatedBy,UpdatedOn,UpdatedBy")] ProductStoreSpecific productStoreSpecific)
        {
            productStoreSpecific.Id = 0;
            if (ModelState.IsValid)
            {
                if (User != null)
                {
                    var userFullName = User.Claims.FirstOrDefault(x => x.Type == $"name").Value;
                    productStoreSpecific.CreatedBy = userFullName;
                }

                productStoreSpecific.CreatedOn = DateTime.Now;

                productStoreSpecific.ProductId = id;
                _dbWriteService.Add(productStoreSpecific);
                await _dbWriteService.SaveChangesAsync();

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

                RequestEmail requestEmail = new RequestEmail(_configuration, _dbReadService);
                requestEmail.SendNewRequestToHeadQuarters(request);

                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> CreateRequest([Bind("Id,RequestDescription,RequestTypeId,StatusTypeId,UserId,SupplierId,StoreId,CreatedOn,CreatedBy,UpdatedOn,UpdatedBy")] Request request)
        {
            if (ModelState.IsValid)
            {
                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.CreatedBy = userFullName;
                }

                request.CreatedOn = DateTime.Now;

                var status = await _dbReadService.GetSingleRecordAsync <StatusType>(s => s.StatusTypeName.Equals("New Request"));

                request.StatusTypeId = status.Id;

                _dbWriteService.Add(request);
                await _dbWriteService.SaveChangesAsync();
            }

            RequestDto.RequestId = request.Id;

            return(RedirectToAction("CreateProduct", "Products", new { id = request.Id }));
        }
        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 }));
        }
示例#7
0
        public async Task <IActionResult> Create([Bind("Id,ContainerSizeTypeName")] ContainerSizeType containerSizeType)
        {
            if (ModelState.IsValid)
            {
                _dbWriteService.Add(containerSizeType);

                await _dbWriteService.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(containerSizeType));
        }
示例#8
0
        private void CreateUserProfile(AspNetUser user)
        {
            var userProfile = new UserProfile
            {
                UserId    = user.Id,
                Email     = user.Email,
                CreatedOn = DateTime.Now,
                CreatedBy = "REGISTRATION_PROCESS"
            };

            _dbWrite.Add <UserProfile>(userProfile);
            _dbWrite.SaveChanges();
        }
示例#9
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            var success = await _dbWriteService.Add(Input);

            if (!success)
            {
                return(Page());
            }
            StatusMessage = $"Created a new Band: {Input.Name}.";
            return(RedirectToPage("Index"));
        }
示例#10
0
        public async Task <IActionResult> OnPostAsync()
        {
            //Retrive data for drop downs and store them in view data
            StoreSelectListInViewData();

            //Retreive the names for item, style, and location based on Ids
            var itemNumber = _dbReadService.Get <Product>(Input.ProductId)?.ItemNumber;
            var style      = _dbReadService.Get <Style>(Input.StyleId)?.Name;
            var location   = _dbReadService.Get <Location>(Input.LocationId)?.Name;

            //check if composite primary key already exists in the database
            var pi = _dbReadService.Get <ProductInventory>(Input.ProductId, Input.StyleId, Input.LocationId);

            if (pi != null)
            {
                ModelState.AddModelError("DuplicateKey", "Duplicate Keys");

                ErrorMsg = "There is already an inventory entry for " +
                           $"item # <strong>{itemNumber}</strong> with style of <strong>{style}</strong> at <strong>{location}</strong>." +
                           " Please select a different item number, style, and location combination or click " +
                           $@"<a href='/ProductInventories/Edit?ProductId={Input.ProductId}&StyleId={Input.StyleId}&LocationId={Input.StyleId}'>here</a>" +
                           " to edit the existing entry.";

                MsgInHtmlString = new HtmlString(ErrorMsg);
                return(Page());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var result = await _dbWriteService.Add(Input);

                    if (result)
                    {
                        //Message sent back to Index razor page
                        StatusMessage = $"Created a new inventory entry for Item {itemNumber}, Style: {style}, Location: {location}.";
                        return(RedirectToPage("Index"));
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }
            //something failed, redisplay the form
            return(Page());
        }
示例#11
0
        public async Task <IActionResult> OnPostAddAsync(string userId)
        {
            try
            {
                _dbWriteService.Add(new UserCourse {
                    CourseId = CourseId, UserId = userId
                });
                var succeeded = await _dbWriteService.SaveChangesAsync();
            }
            catch
            {
            }
            await FillViewData(userId);

            return(Page());
        }
示例#12
0
        public async Task <IActionResult> Create([Bind("Id,NoteId,NoteListItem1,CreatedOn,CreatedBy")] NoteListItem noteListItem)
        {
            if (ModelState.IsValid)
            {
                noteListItem.CreatedBy = User.Identity.Name;
                noteListItem.CreatedOn = DateTime.Now;
                _dbWrite.Add(noteListItem);
                await _dbWrite.SaveChangesAsync();

                noteId = 0;
                return(RedirectToAction("Index", "NoteListItems", new { Id = noteListItem.NoteId }));
            }
            ViewData["NoteId"] = new SelectList(_context.Note, "Id", "Id", noteListItem.NoteId);

            return(View(noteListItem));
        }
示例#13
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                var result = await _dbWriteService.Add(Input);

                if (result)
                {
                    //Message sent back to Index razor page
                    StatusMessage = $"Created a new category: {Input.Name}";
                    return(RedirectToPage("Index"));
                }
            }
            //something failed, redisplay the form
            return(Page());
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                var success = await _dbWriteService.Add(Input);

                if (success)
                {
                    StatusMessage = $"Created a new Instructor: {Input.Name}.";
                    return(RedirectToPage("Index"));
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                Input.CourseId = _dbReadService.Get <Module>(Input.ModuleId).CourseId;
                var success = await _dbWriteService.Add(Input);

                if (success)
                {
                    StatusMessage = $"Created a new Download: {Input.Title}.";
                    return(RedirectToPage("Index"));
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
示例#16
0
        public async Task <int> CreateAsync <TSource, TDestination>(TSource item) where TSource : class where TDestination : class
        {
            try
            {
                var entity = _mapper.Map <TDestination>(item);
                _dbWrite.Add(entity);
                var succeeded = await _dbWrite.SaveChangesAsync();

                if (succeeded)
                {
                    return((int)entity.GetType().GetProperty("Id").GetValue(entity));
                }
            }
            catch { }

            return(-1);
        }
示例#17
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            Input.AlbumId  = _dbReadService.Get <Album>(Input.AlbumId).Id;
            Input.Position = 1;
            var success = await _dbWriteService.Add(Input);

            if (!success)
            {
                return(Page());
            }
            StatusMessage = $"Created a new Video: {Input.Title}.";
            return(RedirectToPage("Index"));
        }
示例#18
0
        public async Task <IActionResult> OnPostAsync()
        {
            Input.Band  = _dbReadService.Get <Band>(Input.BandId, true);
            Input.Genre = _dbReadService.Get <Genre>(Input.Band.GenreId, true);
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            var success = await _dbWriteService.Add(Input);

            if (!success)
            {
                return(Page());
            }
            StatusMessage = $"Created a new Album: {Input.Title}.";
            return(RedirectToPage("Index"));
        }
示例#19
0
        public async Task <IActionResult> CreateNote(int?id, [Bind("Id,NoteText,SendEmailRequestor,SendEmailSupplier,RequestId,CreatedOn,CreatedBy,UpdatedOn,UpdatedBy")] Note note)
        {
            note.Id = 0;
            if (ModelState.IsValid)
            {
                if (User != null)
                {
                    var userFullName = User.Claims.FirstOrDefault(x => x.Type == $"name").Value;
                    note.CreatedBy = userFullName;
                }

                note.CreatedOn = DateTime.Now;
                note.RequestId = id;
                _dbWriteService.Add(note);

                await _dbWriteService.SaveChangesAsync();

                var request = await _dbReadService.GetSingleRecordAsync <Request>(r => r.Id.Equals(id));

                if (note.SendEmailSupplier == true)
                {
                    RequestEmail emailSupplier = new RequestEmail(_configuration, _dbReadService);
                    emailSupplier.SendNewNoteEmailToSuppliers(request, note);
                }

                if (note.SendEmailRequestor == true)
                {
                    RequestEmail emailOriginator = new RequestEmail(_configuration, _dbReadService);
                    var          user            = await _dbReadService.GetSingleRecordAsync <Entity.Models.User>(u => u.EmailAddress.Equals(request.UserId));

                    if (user != null)
                    {
                        if (user.SupplierId != null && user.SupplierId > 0)
                        {
                            emailOriginator.SendNewNoteEmailToOriginatingUser(request, note, user.SupplierId);
                        }
                        else
                        {
                            emailOriginator.SendNewNoteEmailToOriginatingUser(request, note);
                        }
                    }
                }
            }
            return(RedirectToAction("Index", "Notes", new { id = note.RequestId }));
        }
示例#20
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            var success = await _dbWriteService.Add(Input);

            if (!success)
            {
                return(Page());
            }
            var genre = _dbReadService.Get <Genre>(Input.GenreId);
            var user  = _userService.GetUser(Input.UserId);

            StatusMessage = $"User-Genre combination {genre.Title}/{user.Email} was created.";
            return(RedirectToPage("Index"));
        }
        public async Task <IActionResult> Create([Bind("Id,FamilyLastName,Title,Picture,PictureContentType,Description,InvitationCode,FamilyAdminUserProfileId,CreatedOn,CreatedBy")] Family family, IFormFile file, string emailInvite)
        {
            if (!_signInManager.IsSignedIn(User))
            {
                return(RedirectToPage("/Account/Login", new { Area = "Identity" }));
            }

            if (!string.IsNullOrEmpty(emailInvite))
            {
                EmailHelper.SendSubscriberMessage(emailInvite, Constants.EmailInvitationCode);
            }

            // MediaHelper does the work, just send the file over.
            family.Picture = MediaHelper.ResizeImageFromFile(file);

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

            family.PictureContentType       = file.ContentType;
            family.CreatedBy                = User.Identity.Name;
            family.CreatedOn                = DateTime.Now;
            family.FamilyAdminUserProfileId = UserData.UserProfileId;

            if (ModelState.IsValid)
            {
                _dbWrite.Add <Family>(family);
                await _dbWrite.SaveChangesAsync();
            }

            var user = _dbRead.GetSingleRecordAsync <UserProfile>(u => u.Id.Equals(UserData.UserProfileId)).Result;

            user.FamilyId = family.Id;
            await _dbWrite.SaveChangesAsync();

            UserData.FamilyId = family.Id;
            UserData.FamilyProfileComplete = true;

            return(RedirectToAction("Details", "Families", new { id = user.FamilyId }));
        }
示例#22
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                var success = await _dbWriteService.Add(Input);

                if (success)
                {
                    var user   = _userService.GetUser(Input.UserId);
                    var course = _dbReadService.Get <Course>(Input.CourseId);
                    StatusMessage = $"User-Course combination [{course.Title} | {user.Email}] was created.";
                    return(RedirectToPage("Index"));
                }
            }

            // If we got this far, something failed, redisplay form
            ViewData["Users"]   = _dbReadService.GetSelectList <User>("Id", "Email");
            ViewData["Courses"] = _dbReadService.GetSelectList <Course>("Id", "Title");
            return(Page());
        }
示例#23
0
        public async Task <IActionResult> Create([Bind("Id,SupplierName,SupplierEmail,CreatedOn,CreatedBy,UpdatedOn,UpdatedBy")] Supplier supplier)
        {
            if (ModelState.IsValid)
            {
                if (User != null)
                {
                    var userFullName = User.Claims.FirstOrDefault(x => x.Type == $"name").Value;
                    supplier.CreatedBy = userFullName;
                }

                supplier.CreatedOn = DateTime.Now;

                _dbWriteService.Add(supplier);

                await _dbWriteService.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(supplier));
        }
示例#24
0
        public async Task <IActionResult> Create([Bind("Id,SupplierId,FirstName,LastName,EmailAddress,AuthId,CreatedOn,CreatedBy,UpdatedOn,UpdatedBy")] User user)
        {
            var userFullName = User.Claims.FirstOrDefault(x => x.Type == $"name").Value;

            if (ModelState.IsValid)
            {
                if (User != null)
                {
                    user.CreatedBy = userFullName;
                }

                user.CreatedOn = DateTime.Now;

                var graphClient = new GraphClient(Configuration, true);
                var password    = string.Empty;
                var graphResult = graphClient.CreateUser(user, out password);

                if (graphResult)
                {
                    _dbWriteService.Add(user);

                    var saveResult = await _dbWriteService.SaveChangesAsync();

                    if (saveResult)
                    {
                        var userEmail = new PM.Business.Email.User(Configuration);

                        userEmail.SendWelcomeEmail(user, password);

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

                    // Failed to save to the database, delete the user from the directory.
                    graphClient.DeleteUser(user.AuthId);
                }
            }

            ViewData["SupplierId"] = new SelectList(_context.Supplier, "Id", "SupplierName", user.SupplierId);

            return(View(user));
        }
示例#25
0
        public async Task <IActionResult> Create([Bind("Id,Title,Text,Advanced,DueDate,UserProfileId,ShareToFam,CreatedOn,CreatedBy")] Note note)
        {
            if (ModelState.IsValid)
            {
                note.UserProfileId = UserData.UserProfileId;
                note.CreatedOn     = DateTime.Now;
                note.CreatedBy     = UserData.UserId;

                _dbWrite.Add(note);
                await _dbWrite.SaveChangesAsync();

                if (note.Advanced == true)
                {
                    return(RedirectToAction("Create", "NoteListItems", new { noteid = note.Id }));
                }

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserProfileId"] = new SelectList(_context.UserProfile, "Id", "UserId", note.UserProfileId);

            return(View(note));
        }