Exemplo n.º 1
0
        public ActionResult ContactUs(ContactViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            try
            {
                ContactU contact = new ContactU()
                {
                    EmailId      = model.EmailId,
                    Description  = model.Description,
                    MobileNumber = model.MobileNumber,
                    Name         = model.Name,
                    CreatedDate  = DateTime.Now,
                    IsActive     = true,
                    ModifiedDate = DateTime.Now
                };
                _contactRepo.Create(contact);
                _contactRepo.SaveChanges();
            }
            catch (Exception ex)
            {
            }
            return(View("Contacts"));
        }
        public ActionResult Post(ContactUs model)
        {
            // ContactUs model = new ContactUs { Name = "abc", Email="aaaa", Address="aaaaa" };

            try
            {
                if (string.IsNullOrWhiteSpace(model.Name))
                {
                    return(BadRequest("Please enter Name"));
                }
                else if (string.IsNullOrWhiteSpace(model.Email))
                {
                    return(BadRequest("Please enter Email"));
                }
                else if (string.IsNullOrWhiteSpace(model.Address))
                {
                    return(BadRequest("Please enter Address"));
                }

                _contactUsRepository.Create(model);

                return(Ok("Your product has been added successfully"));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.ToString()));
            }
        }