示例#1
0
        public async Task <IActionResult> Create(int?appointmentId, [Bind("AppointmentDetailId,AppointmentId,ProductId,ProcedureMinutes,RetailPrice,Quantity,Discount,Total,Comments")] AppointmentDetail appointmentDetail)
        {
            TempData["id"] = ViewBag.id;
            if (TempData["id"] != null)
            {
                appointmentDetail.AppointmentId = Convert.ToInt32(TempData["id"]);
            }
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(appointmentDetail);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                ViewData["AppointmentId"] = new SelectList(_context.Appointment, "AppointmentId", "AppointmentId", appointmentDetail.AppointmentId);
                ViewData["ProductId"]     = new SelectList(_context.Product, "ProductId", "Name", appointmentDetail.ProductId);
                return(View(appointmentDetail));
            }
            catch (Exception ex)
            {
                //write this down
                TempData["Message"] = ex.InnerException.Message;
                //write this down
                return(View(appointmentDetail));
            }
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("ProductId,IsProcedure,Name,Description,RetailPrice,WholesalePrice,ProcedureMinutes")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
示例#3
0
        public async Task <IActionResult> Create([Bind("CustomerId,Name,Phone,Email,StreetAddress,City,PostalCode,Province,PreferredStylist,Comments,CanAdvertiseOnline")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
示例#4
0
        public async Task <IActionResult> Create([Bind("StaffId,CustomerId,DateHired,DateTerminated,ReasonForTermination,IsStylist,HourlyChargeoutRate,HourlySalary,Comments")] Staff staff)
        {
            if (ModelState.IsValid)
            {
                _context.Add(staff);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customer, "CustomerId", "Name", staff.CustomerId);
            return(View(staff));
        }
        public async Task <IActionResult> Create([Bind("AppointmentId,CustomerId,StaffId,AppointmentDate,ScheduledStartTime,ProcedureMinutes,ScheduledEndTime,FinalTotal,TotalBeforeTax,TaxRate,Completed")] Appointment appointment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(appointment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customer, "CustomerId", "Name", appointment.CustomerId);
            ViewData["StaffId"]    = new SelectList(_context.Staff, "StaffId", "StaffId", appointment.StaffId);
            return(View(appointment));
        }
示例#6
0
        public async Task <IActionResult> Create([Bind("AppointmentDetailId,AppointmentId,ProductId,ProcedureMinutes,RetailPrice,Quantity,Discount,Total,Comments")] AppointmentDetail appointmentDetail)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(appointmentDetail);
                    await _context.SaveChangesAsync();

                    TempData["message"] = "Appointment Created";
                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception ex)
            {
                TempData["message"] = "Create Failed" + ex.GetBaseException().Message;
            }
            ViewData["AppointmentId"] = new SelectList(_context.Appointment, "AppointmentId", "AppointmentId", appointmentDetail.AppointmentId);
            ViewData["ProductId"]     = new SelectList(_context.Product, "ProductId", "Name", appointmentDetail.ProductId);
            return(View(appointmentDetail));
        }
        public async Task <IActionResult> Create(int apptid, [Bind("AppointmentDetailId,AppointmentId,ProductId,ProcedureMinutes,RetailPrice,Quantity,Discount,Total,Comments")] AppointmentDetail appointmentDetail)
        {
            //Check for null before converting to int
            if (TempData["AppointmentId"] != null)
            {
                appointmentDetail.AppointmentId = Convert.ToInt32(TempData["AppointmentId"]);
            }

            //appointmentDetail.AppointmentId = apptid; //throws FK error??

            //Set defaults to zero as these are required attributes
            appointmentDetail.RetailPrice      = 0;
            appointmentDetail.ProcedureMinutes = 0;
            appointmentDetail.Total            = 0;

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

                    TempData["message"] = "Saved to DB";
                    return(RedirectToAction(nameof(Index)));
                }
            }

            catch (Exception ex)
            {
                TempData["message"] = ex.InnerException.Message;
            }

            ViewData["AppointmentId"] = new SelectList(_context.Appointment, "AppointmentId", "AppointmentId", appointmentDetail.AppointmentId);
            ViewData["ProductId"]     = new SelectList(_context.Product, "ProductId", "Name", appointmentDetail.ProductId);

            TempData["message"] = "Model Validation dint pass";
            return(View(appointmentDetail));
        }