public JsonResult AddOrUpdateAppointment(AddOrUpdateAppointmentModel model)
        {
            //Validasyon
            if (model.Id == 0)
            {
                //    var check = _context.Appointments.Where(x => x.StartDate == model.StartDate && x.EndDate == model.EndDate);
                //if (check != null)
                //{
                //    return Json("Error");

                //}
                Appointment entity = new Appointment()
                {
                    Surname     = model.Surname,
                    PhoneNumber = model.PhoneNumber,
                    Plaka       = model.Plaka,
                    il          = model.il,
                    Name        = model.Name,
                    CreatedDate = DateTime.Now,
                    StartDate   = model.StartDate,
                    Id          = model.Id,
                    CarName     = model.CarName,
                    CarModel    = model.CarModel,
                    Description = model.Description,
                };

                _context.Add(entity);
                _context.SaveChanges();
            }
            else
            {
                var entity = _context.Appointments.SingleOrDefault(x => x.Id == model.Id);
                if (entity == null)
                {
                    return(Json("Güncellenecek veri bulunamadı."));
                }
                entity.Surname     = model.Surname;
                entity.PhoneNumber = model.PhoneNumber;
                entity.Plaka       = model.Plaka;
                entity.il          = model.il;
                entity.Name        = model.Name;
                entity.UpdatedDate = DateTime.Now;
                entity.CarName     = model.CarName;
                entity.CarModel    = model.CarModel;
                entity.Description = model.Description;
                entity.StartDate   = model.StartDate;

                entity.UserId = model.UserId;

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

            return(Json("200"));
        }
        public IActionResult Register()
        {
            var cityList = _context.Cities.ToList();
            AddOrUpdateAppointmentModel model = new AddOrUpdateAppointmentModel()
            {
                City = cityList.Select(n => new SelectListItem
                {
                    Value = n.Id.ToString(),
                    Text  = $" {n.Name} "
                }).ToList()
            };

            return(View(model));
        }
Exemple #3
0
        public JsonResult AddOrUpdateAppointment(AddOrUpdateAppointmentModel model)
        {
            //Validasyon
            if (model.Id == 0)
            {
                Appointment entity = new Appointment()
                {
                    CreatedDate    = DateTime.Now,
                    StartDate      = model.StartDate,
                    EndDate        = model.EndDate,
                    PatientName    = model.PatientName,
                    PatientSurname = model.PatientSurname,
                    Description    = model.Description,
                    UserId         = model.UserId
                };

                _context.Add(entity);
                _context.SaveChanges();
            }
            else
            {
                var entity = _context.Appointments.SingleOrDefault(x => x.Id == model.Id);
                if (entity == null)
                {
                    return(Json("Güncellenecek veri bulunamadı."));
                }
                entity.UpdatedDate    = DateTime.Now;
                entity.PatientName    = model.PatientName;
                entity.PatientSurname = model.PatientSurname;
                entity.Description    = model.Description;
                entity.StartDate      = model.StartDate;
                entity.EndDate        = model.EndDate;
                entity.UserId         = model.UserId;

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

            return(Json("200"));
        }
Exemple #4
0
        public JsonResult AddOrUpdateAppoinment(AddOrUpdateAppointmentModel model)
        {
            if (model.Id == 0)
            {
                Appointment appointment = model.Adapt <Appointment>();
                appointment.CreatedDate = DateTime.Now;

                _context.Add(appointment);
                _context.SaveChanges();
            }
            else
            {
                var appointment = model.Adapt <Appointment>();

                appointment.UpdateDate = DateTime.Now;

                _context.Update(appointment);

                _context.SaveChanges();
            }

            return(Json("200"));
        }