예제 #1
0
 public ActionResult AddSave(string surname, string telephone)
 {
     phoneBookContext = new PhoneBookContext();
     phoneBookContext.Add(surname, telephone);
     ViewBag.PhoneBooks = phoneBookContext.PhoneBooks;
     return(View("Index"));
 }
예제 #2
0
 public ActionResult AddSave(string surname, string telephone)
 {
     phoneBookContext = new PhoneBookContext(Server.MapPath("~/Models/Data.json"));
     phoneBookContext.Add(surname, telephone);
     ViewBag.PhoneBooks = phoneBookContext.PhoneBooks;
     return(View("Index"));
 }
        public Person AddPerson(Person person)
        {
            person = _phoneBookContext.Add(person).Entity;

            _phoneBookContext.SaveChanges();

            return(person);
        }
예제 #4
0
        public async Task <IActionResult> Create([Bind("ClienteId,Nome,Cpf,Cpnj,Email,TelefoneCelular,TelefoneResidencial,TelefoneComercial,Endereco")] Clientes clientes)
        {
            if (ModelState.IsValid)
            {
                _context.Add(clientes);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(clientes));
        }
        public async Task <IActionResult> Create([Bind("ContactId,Email,FirstName,LastName,Phone")] Contacts contacts)
        {
            if (ModelState.IsValid)
            {
                _context.Add(contacts);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(contacts));
        }
예제 #6
0
        public async Task <IActionResult> Create([Bind("Id,Number,ContactId,TypePhoneId")] Phone phone)
        {
            if (ModelState.IsValid)
            {
                _context.Add(phone);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", "Contact", new { id = phone.ContactId }));
            }
            ViewData["TypePhoneId"] = new SelectList(_context.TypePhones, "Id", "Name", phone.TypePhoneId);
            return(PartialView(phone));
        }
예제 #7
0
        public ActionResult <Person> NewPerson(Person person)
        {
            if (person == null)
            {
                return(NotFound());
            }

            _PhoneBookContext.Add(person);
            _PhoneBookContext.SaveChanges();

            return(Ok());
        }
예제 #8
0
        public IActionResult Add(DTO.Person person)
        {
            using (var context = new PhoneBookContext())
            {
                var modelPerson = _mapper.Map <Person>(person);

                if (modelPerson != null)
                {
                    var newPerson = context.Add(modelPerson);
                    context.SaveChanges();

                    return(Json(new { Success = true, newPerson.Entity.PersonId }));
                }
            }

            return(NotFound());
        }
예제 #9
0
        public IActionResult Add(DTO.Phone phone)
        {
            using (var context = new PhoneBookContext())
            {
                var modelPhone = _mapper.Map <Phone>(phone);

                if (modelPhone != null)
                {
                    var newPhone = context.Add(modelPhone);
                    context.SaveChanges();

                    return(Json(new { success = true, personId = newPhone.Entity.PersonId }));
                }
            }

            return(NotFound());
        }
예제 #10
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Group @group)
        {
            var  name = User.Identity.Name;
            User user = _context.Users.FirstOrDefault(u => u.UserName == name);

            if (user != null)
            {
                ViewData["NameUser"] = user.Surname + " " + user.Name;
            }

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

                return(RedirectToAction(nameof(Index)));
            }
            return(View(@group));
        }
예제 #11
0
        public async Task <IActionResult> Create([Bind("Id,Surname,Name,Patronymic,Address,Job,Position,Email,Skype,GroupId")] Contact contact)
        {
            var name = User.Identity.Name;

            User user = _context.Users.FirstOrDefault(u => u.UserName == name);

            if (ModelState.IsValid && user != null)
            {
                ViewData["NameUser"] = user.Surname + " " + user.Name;

                contact.UserId = user.Id;
                _context.Add(contact);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Home"));
            }
            ViewData["GroupId"] = new SelectList(_context.Groups, "Id", "Name", contact.GroupId);

            return(View(contact));
        }
예제 #12
0
        public async Task <IActionResult> Add([Bind("Id,Type,Number,PersonId")] Phone phone)
        {
            if (ModelState.IsValid)
            {
                /*if (phone.PersonId != null)
                 * {
                 *  Person person = _context.Persons.First(p => p.Id == phone.Person.Id);
                 *
                 *  phone.Person = person;
                 * }*/


                _context.Add(phone);
                await _context.SaveChangesAsync();

                return(new RedirectToActionResult(nameof(Index), "Phones", new { pid = phone.PersonId }));
            }
            ViewData["PersonId"] = phone.PersonId;
            return(View(phone));
        }
예제 #13
0
        public IActionResult AddUser([FromForm] AddUserPM model)
        {
            if (ModelState.IsValid)
            {
                User user = new User();

                user.Name    = model.Name;
                user.SurName = model.SurName;
                user.Company = model.Company;

                _phoneBookContext.Add(user);
                _phoneBookContext.SaveChanges();

                model.ID = user.ID;

                return(Ok(model));
            }
            else
            {
                return(BadRequest(ModelState.Values));
            }
        }
예제 #14
0
        public async Task <IActionResult> Create([Bind("Type,FirstName,LastName,Image,Address,Description")] Person person)
        {
            if (ModelState.IsValid)
            {
                person.Picture = person.Image?.FileName;
                var Image = person.Image;
                person.Image = null;
                string ImageName = System.IO.Path.GetFileName(Image.FileName);
                var    filePath  = Path.Combine("C:\\Users\\Mohammad\\source\\repos\\Phonebook\\wwwroot\\images\\", ImageName);

                using (var stream = System.IO.File.Create(filePath))
                {
                    Image.CopyTo(stream);
                }

                _context.Add(person);
                await _context.SaveChangesAsync();

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

            return(View(person));
        }
예제 #15
0
 public async Task InsertContact(Contact ctt)
 {
     _context.Add(ctt);
     await _context.SaveChangesAsync();
 }