Ejemplo n.º 1
0
        public IHttpActionResult Delete(long Id)
        {
            IHttpActionResult response;
            bool status = this.contactsService.Delete(Id);

            if (status)
            {
                return(Ok());
            }
            response = new CustomMessageResult("Sorry, Contact can not be Updated. Please try later !");
            return(response);
        }
        public async Task <ActionResult <CustomMessageResult> > CustomerMessage(ContactUsModel contactUsModel)
        {
            var          result       = new Result <CustomMessageResult>();
            ContactEmail contactEmail = new ContactEmail();

            _mapper.Map(contactUsModel, contactEmail);
            await _context.ContactEmail.AddAsync(contactEmail);

            try
            {
                var emailExist = await _context.ContactEmail.Where(x => x.Name == null && x.Email == contactUsModel.Email).FirstOrDefaultAsync();

                if (emailExist == null)
                {
                    Guid  coupon   = Guid.NewGuid();
                    Popup newPopUp = new Popup
                    {
                        Coupon  = coupon.ToString().Substring(0, 8),
                        IsValid = 1
                    };
                    await _context.Popups.AddAsync(newPopUp);

                    SendEmailCustomer(contactUsModel, newPopUp.Coupon);
                    await _context.SaveChangesAsync();

                    CustomMessageResult messageResult = new CustomMessageResult
                    {
                        email       = contactEmail.Email,
                        phoneNumber = contactEmail.PhoneNumber,
                        findUs      = contactEmail.FindUs,
                        coupon      = newPopUp.Coupon
                    };
                    await UserSubscribe(contactEmail.Email);

                    result.Data = messageResult;
                }
                else
                {
                    result.IsSuccess    = false;
                    result.ErrorMessage = "This email already subscribed.";
                    return(BadRequest(result));
                }
            }
            catch (Exception e)
            {
                result.ErrorMessage = e.Message;
                result.IsFound      = false;
                return(BadRequest(result));
            }
            return(Ok(result));
        }
Ejemplo n.º 3
0
        public IHttpActionResult Update(Contact model)
        {
            IHttpActionResult response;

            if (ModelState.IsValid)
            {
                bool status = this.contactsService.Update(model);
                if (status)
                {
                    return(Ok());
                }
                response = new CustomMessageResult("Sorry, Contact can not be Updated. Please try later !");
                return(response);
            }

            HttpResponseMessage responseMsg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);

            response = ResponseMessage(responseMsg);
            return(response);  // implemnted Custom Messdage with additional deatils bac.
        }