Exemplo n.º 1
0
        public async Task <IActionResult> PostCalendar([Bind("Title", "Description", "Date", "CompanyId")] Calendar calendar)
        {
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            if (userId == null)
            {
                return(NotFound());
            }
            var title   = calendar.Title;
            var desc    = calendar.Description;
            var date    = calendar.Date;
            var company = calendar.CompanyId;

            try
            {
                if (ModelState.IsValid)
                {
                    await _context.Calendars.AddAsync(calendar);

                    await _context.SaveChangesAsync();

                    return(Json(new { status = 200, id = calendar.CalendarId }));
                }
            }
            catch (RetryLimitExceededException)
            {
                ModelState.AddModelError("", "Unable to save changes after multiple attempts. Try again, and if the problem persists, see your system administrator.");
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", "Unable to create new event.");
            }
            return(BadRequest(ModelState));
        }
        public async Task <IActionResult> PostAnnouncement([Bind("Title", "Message", "Severity")] Announcement announcement)
        {
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);

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

            try
            {
                if (ModelState.IsValid)
                {
                    await _context.Announcements.AddAsync(announcement);

                    await _context.SaveChangesAsync();
                    await NotifyAllEmployees(announcement);

                    return(Json(new { status = 200, id = announcement.AnnouncementID }));
                }
            }
            catch (RetryLimitExceededException)
            {
                ModelState.AddModelError("", "Unable to save changes after multiple attempts. Try again, and if the problem persists, see your system administrator.");
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", "Unable to create new record.");
            }
            return(BadRequest(ModelState));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("ContactID,FirstName,LastName,JobTitle,CellPhone,WorkPhone,Email,Active,Notes,CompanyID")] Contact contact,
                                                 string[] selectedOptions)
        {
            //Get the URL with the last filter, sort and page parameters
            ViewData["returnURL"] = MaintainURL.ReturnURL(HttpContext, "Contacts");

            //ViewData["returnURL"] = returnURL;
            try
            {
                // Adding the multi select categories
                if (selectedOptions != null)
                {
                    foreach (var category in selectedOptions)
                    {
                        var categoryToAdd = new ContactCategories {
                            ContactID = contact.ContactID, CategoriesID = int.Parse(category)
                        };
                        contact.ContactCategories.Add(categoryToAdd);
                    }
                }

                if (ModelState.IsValid)
                {
                    _context.Add(contact);
                    await _context.SaveChangesAsync();

                    //if(String.IsNullOrEmpty(returnURL))
                    //{
                    //    return RedirectToAction(nameof(Index), new { CType = CType });
                    //}
                    //else
                    //{
                    //    return Redirect(returnURL);
                    //}

                    return(Redirect(ViewData["returnURL"].ToString()));
                }
                ViewData["CompanyID"] = new SelectList(_context.Companies, "CompanyID", "Name", contact.CompanyID);
                return(View(contact));
            }
            catch (RetryLimitExceededException) // Multiple tries
            {
                ModelState.AddModelError("", "Ineffectual save changes after multiple attempts. Try again. If the problem persists, please contact your system administrator.");
            }

            return(View(contact));
        }
        public async Task <IActionResult> DeleteUserAsync(string userId)
        {
            var user = await _userManager.FindByIdAsync(userId);

            await _userManager.DeleteAsync(user);

            _hContext.Employees.FirstOrDefault(e => e.UserId == userId).UserId = String.Empty;
            var result = await _hContext.SaveChangesAsync();

            return(Json(new { result }));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("CompanyID,Name,Location,CreditCheck,DateChecked,BillingTermID,CurrencyID,Phone,Website,BillingAddress1,BillingAddress2,BillingProvinceID,BillingPostalCode,BillingCountryID,ShippingAddress1,ShippingAddress2,ShippingProvinceID,ShippingPostalCode,ShippingCountryID,Customer,CustomerTypeID,Vendor,VendorTypeID,Contractor,ContractorTypeID,Active,Notes")]
                                                 Company company, string CType, string companyTypes)
        {
            //Get the URL with the last filter, sort and page parameters
            ViewData["returnURL"] = MaintainURL.ReturnURL(HttpContext, "Companies");
            //ViewData["returnURL"] = returnURL;
            try
            {
                UpdateCompanyTypes(companyTypes, company);
                if (ModelState.IsValid)
                {
                    _context.Add(company);
                    await _context.SaveChangesAsync();

                    //If no referrer then go back to index
                    //if (String.IsNullOrEmpty(returnURL))
                    //{
                    //    return RedirectToAction(nameof(Index), new { CType = CType });
                    //}
                    //else
                    //{
                    //    return Redirect(returnURL);
                    //}
                    //return RedirectToAction("Details", new { company.CompanyID });
                    return(Redirect(ViewData["returnURL"].ToString()));
                }
            }
            catch (RetryLimitExceededException)
            {
                ModelState.AddModelError("", "Unable to save changes after multiple attempts. Try again, and if the problem persists, see your system administrator.");
            }
            catch (Exception)
            {
                ModelState.AddModelError("", "Unable to create new record.");
            }

            return(View(company));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Create(
            [Bind("FirstName,LastName,JobPositionID,EmploymentTypeID,EmployeeAddress1,EmployeeAddress2,EmployeeProvinceID,EmployeePostalCode,EmployeeCountryID,CellPhone,WorkPhone,Email,DOB,Wage,Expense,DateJoined,KeyFob,EmergencyContactName,EmergencyContactPhone,Active,Notes,UserId")] Employee employee,
            string userPassword,
            string userRepeatPassword,
            bool isUser)
        {
            //Get the URL with the last filter, sort and page parameters
            ViewData["returnURL"] = MaintainURL.ReturnURL(HttpContext, "Employees");

            if (ModelState.IsValid)
            {
                try
                {
                    if (isUser)
                    {
                        employee.UserId = await HandleIdentityCreation(employee.Email, userPassword, userRepeatPassword);
                    }
                    if (!(isUser && string.IsNullOrEmpty(employee.UserId)))
                    {
                        _context.Add(employee);
                        await _context.SaveChangesAsync();

                        //return RedirectToAction(nameof(Index));
                        return(Redirect(ViewData["returnURL"].ToString()));
                    }
                }
                catch (Exception e)
                {
                    _context.HandleDatabaseException(e, ModelState);
                }
            }
            ViewData["EmployeeCountryID"]  = GetCountriesSelectList(employee.EmployeeCountryID);
            ViewData["EmployeeProvinceID"] = GetProvincesSelectList(employee.EmployeeProvinceID);
            ViewData["EmploymentTypeID"]   = GetEmploymentTypesSelectList(employee.EmploymentTypeID);
            ViewData["JobPositionID"]      = GetPositionsSelectList(employee.JobPositionID);
            return(View(employee));
        }