예제 #1
0
        public async Task <IActionResult> AddPhoneNumber([FromBody()] PhoneNumberViewModel item)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                else
                {
                    var PhoneBook = await _PhoneBookApi.GetFirstPhoneBook();

                    item.PhoneBookId = PhoneBook.Id;
                    await _PhoneNumberApi.AddPhoneNumber(item.ReverseMap());

                    return(Ok(new { message = "PhoneNumber is added successfully." }));
                }
            }

            catch (Exception ex)
            {
                _loggingApi.Add(new SYS_Error()
                {
                    Message = ex.Message, StackTrace = ex.StackTrace, CreatedDate = DateTime.Now
                });
                await _loggingApi.Commit();

                return(NotFound(new { message = "An error occured" }));
            }
        }
예제 #2
0
        public async Task <IActionResult> UpdatePhoneNumber(int id, [FromBody()] PhoneNumberViewModel item)
        {
            try
            {
                if (!ModelState.IsValid || item == null || id == 0)
                {
                    return(BadRequest(ModelState));
                }

                else
                {
                    var updateditem = item.ReverseMap();

                    var phonebook = await _PhoneBookApi.GetFirstPhoneBook();

                    var number = await _PhoneNumberApi.GetPhoneNumberByID(id);

                    if (number == null)
                    {
                        return(NotFound(new { message = "Phone number not found" }));
                    }

                    number.PhoneBookId = phonebook.Id;
                    number.Name        = updateditem.Name;
                    number.Email       = updateditem.Email;
                    number.Number      = updateditem.Number;

                    await _PhoneNumberApi.UpdatePhoneNumber(number);

                    var updatednumber = new PhoneNumberViewModel(number);

                    return(Ok(new { message = "PhoneNumber is updated successfully." }));
                }
            }
            catch (Exception ex)
            {
                _loggingApi.Add(new SYS_Error()
                {
                    Message = ex.Message, StackTrace = ex.StackTrace, CreatedDate = DateTime.Now
                });
                await _loggingApi.Commit();

                return(NotFound(new { message = "An error occured" }));
            }
        }