예제 #1
0
        public async Task <IActionResult> Create(Contacts contacts)
        {
            if (contacts.ContactType == Contacts.ContactTypes.Location)
            {
                if (!ValidateLocationValues(contacts.ContactText))
                {
                    return(NotFound("Lütfen Geçerli Bir Lokasyon Giriniz!"));
                }
            }
            else if (contacts.ContactType == Contacts.ContactTypes.Mail)
            {
                if (!new EmailAddressAttribute().IsValid(contacts.ContactText))
                {
                    return(NotFound("Lütfen Geçerli Bir Mail Adresi Giriniz!"));
                }
            }
            else if (contacts.ContactType == Contacts.ContactTypes.Phone)
            {
                if (!new PhoneAttribute().IsValid(contacts.ContactText))
                {
                    return(NotFound("Lütfen Geçerli Bir Telefon Numarası Giriniz!"));
                }
            }
            _context.Add(contacts);
            await _context.SaveChangesAsync();

            return(Ok(contacts));
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("Id,ConfigrationId,DefectInPhone,IsRepairable,RepairDate")] Repair repair)
        {
            if (ModelState.IsValid)
            {
                _context.Add(repair);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(repair));
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("PhoneId,NameOfPhone,Company,Cost,Stock")] Phone phone)
        {
            if (ModelState.IsValid)
            {
                _context.Add(phone);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(phone));
        }
예제 #4
0
        public async Task <IActionResult> Create([Bind("Id,Model,PhoneId,Storage,RAM")] Configration configration)
        {
            if (ModelState.IsValid)
            {
                _context.Add(configration);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(configration));
        }
예제 #5
0
        public async Task <IActionResult> PostUser([FromBody] User newUser)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Values.Select(state => state.Errors)));
            }
            _context.Users.Add(newUser);
            await _context.SaveChangesAsync();

            return(Created(newUser));
        }
예제 #6
0
        public async Task <IActionResult> Post([FromBody] Phone phone, [FromODataUri] int userId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            phone.User = _context.Users.Find(userId);
            _context.Phones.Add(phone);
            await _context.SaveChangesAsync();

            return(Created(phone));
        }