public async Task <ActionResult> Create([Bind(Include = "Id,Type,Subject,BeginDateTime,EndDateTime,Place,State")] Note note)
        {
            if (note.BeginDateTime < DateTime.Now)
            {
                ModelState.AddModelError("BeginDateTime", "Дата должна быть больше текущей");
            }
            if (note.EndDateTime < DateTime.Now)
            {
                ModelState.AddModelError("EndDateTime", "Дата должна быть больше текущей");
            }
            if (note.EndDateTime <= note.BeginDateTime)
            {
                ModelState.AddModelError("BeginDateTime", "Дата начала должна быть меньше даты конца");
            }

            if (ModelState.IsValid)
            {
                db.Notes.Add(note);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(note));
        }
示例#2
0
        public async Task <IActionResult> PutTodo(int id, [FromBody] Todo todo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var list = _context.Lists.FirstOrDefaultAsync(p => p.Id == todo.Id);

            _context.Entry(todo).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }

            catch (DbUpdateConcurrencyException)
            {
                if (!TodoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(NoContent());
        }
        public async Task <IActionResult> PutCustomer(int id, Customer customer)
        {
            if (id != customer.ID)
            {
                return(BadRequest());
            }

            _context.Entry(customer).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#4
0
        public async Task <IActionResult> PutAppointmentType(int id, AppointmentType appointmentType)
        {
            if (id != appointmentType.ID)
            {
                return(BadRequest());
            }

            _context.Entry(appointmentType).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AppointmentTypeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#5
0
        public async Task <T> Create(T entity)
        {
            var result = await context.Set <T>().AddAsync(entity);

            await context.SaveChangesAsync();

            return(result.Entity);
        }
示例#6
0
        public async Task <IActionResult> PutList(int id, [FromBody] List list)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userId = _userManager.GetUserId(User);

            var existinglist = _context.Lists
                               .Include(q => q.Todos)
                               .FirstOrDefault(q => _context.Lists.Any(r => r.Id == id));

            existinglist.IsDone = list.IsDone;
            existinglist.Name   = list.Name;



            _context.Entry(list).State = EntityState.Modified;

            await _context.SaveChangesAsync();

            return(Ok(existinglist));
        }
示例#7
0
        public async Task <ActionResult <Calendar> > DeleteCalendar(string calendarName)
        {
            var calendar = await _context.Calendars.FirstOrDefaultAsync(x => x.CalendarName == calendarName);

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

            _context.Calendars.Remove(calendar);
            await _context.SaveChangesAsync();

            return(calendar);
        }
        public async Task <ActionResult> Create([Bind(Include = "Id,FirstName,LastName,Patronymic,BirthDate,Organization,Position")] Contact contact, List <string> phone, List <string> email, List <string> skype, List <string> other)
        {
            if (ModelState.IsValid)
            {
                db.Contacts.Add(contact);
                await db.SaveChangesAsync();

                foreach (string item in phone)
                {
                    if (item != null && item != "")
                    {
                        db.ContactInformations.Add(new ContactInformation(item, null, null, null, contact.Id));
                        await db.SaveChangesAsync();
                    }
                }
                foreach (string item in email)
                {
                    if (item != null && item != "")
                    {
                        db.ContactInformations.Add(new ContactInformation(null, item, null, null, contact.Id));
                        await db.SaveChangesAsync();
                    }
                }
                foreach (string item in skype)
                {
                    if (item != null && item != "")
                    {
                        db.ContactInformations.Add(new ContactInformation(null, null, item, null, contact.Id));
                        await db.SaveChangesAsync();
                    }
                }
                foreach (string item in other)
                {
                    if (item != null && item != "")
                    {
                        db.ContactInformations.Add(new ContactInformation(null, null, null, item, contact.Id));
                        await db.SaveChangesAsync();
                    }
                }

                return(RedirectToAction("Index"));
            }

            return(View(contact));
        }