public ActionResult CreateContact(ContactViewModel vm)
        {
            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                var contact = vm.ToEntity();

                _contactService.Add(contact);
                try
                {
                    unitOfWork.Commit();
                    return(Json(new
                    {
                        Result = true,
                        Message = "Cảm ơn bạn đã gửi tin nhắn!"
                    }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    unitOfWork.Rollback();
                    LoggingService.Error(ex);
                    return(Json(new
                    {
                        Result = false,
                        Message = "Vui lòng kiểm tra lại thông tin"
                    }, JsonRequestBehavior.AllowGet));
                }
            }
        }
Example #2
0
        /// <summary>
        /// Добавить сотрудника
        /// </summary>
        /// <param name="addedEmployee">DTO добавляемого сотрудника</param>
        /// <returns>Сотрудник</returns>
        public Employee Add(EmployeeDto addedEmployee)
        {
            Contract.Argument.IsNotNull(addedEmployee, nameof(addedEmployee));

            var userId            = _userContextPrtovider.GetUserId();
            var contact           = _contactService.Add(addedEmployee.Contact);
            var passport          = _passportService.Add(addedEmployee.Passport);
            var organization      = _organizationService.Add(addedEmployee.Organization);
            var stateRegistration = _stateRegistrationService.Add(addedEmployee.StateRegistration);

            var newEmployee = _employeeRepository.Create(
                userId: userId,
                managerId: addedEmployee.ManagerId,
                contactId: contact.Id,
                passportId: passport.Id,
                invitationId: null,
                organizationId: organization.Id,
                stateRegistrationId: stateRegistration.Id,
                academicDegree: addedEmployee.AcademicDegree,
                academicRank: addedEmployee.AcademicRank,
                education: addedEmployee.Education,
                position: addedEmployee.Position,
                workPlace: addedEmployee.WorkPlace);

            return(newEmployee);
        }
Example #3
0
        public async Task <IActionResult> Create(ContactViewModel contactViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(contactViewModel));
            }

            var contact = _mapper.Map <Contact>(contactViewModel);

            await _contactService.Add(contact);

            if (!ValidOperation())
            {
                return(View(contactViewModel));
            }


            if (contactViewModel.CompanyId != null)
            {
                return(RedirectToAction("Edit", "Companies", new { id = contactViewModel.CompanyId }));
            }
            else
            {
                return(RedirectToAction("Edit", "Customers", new { id = contactViewModel.CustomerId }));
            }
        }
Example #4
0
 public ContactMobileViewModel Add(ContactMobileViewModel contact)
 {
     Contact contactWithId = _contactService.Add(Mapper.Map<Contact>(contact));
     ContactMobileViewModel contactViewModel = Mapper.Map<ContactMobileViewModel>(contactWithId);
     ObservableContacts.Add(contactViewModel);
     return contactViewModel;
 }
Example #5
0
        public ContactViewModel Add(ContactViewModel contactViewModel)
        {
            var contact = _mapper.Map <ContactViewModel, Contact>(contactViewModel);

            _contactService.Add(contact);
            return(contactViewModel);
        }
        public IActionResult Post([FromServices] IContactService contactService, [FromServices] IUserService userService, [FromRoute] int ownerId, [FromRoute] int userId, [FromRoute] string nick)
        {
            var owner = userService.FindBy(user => user.Id == ownerId);
            var user  = userService.FindBy(user => user.Id == userId);

            if (owner.Count != 1)
            {
                return(NotFound("owner id not found: " + ownerId));
            }

            if (user.Count != 1)
            {
                return(NotFound("user id not found: " + userId));
            }

            Contact c = new Contact()
            {
                Nick          = nick,
                Owner         = owner[0],
                OwnerId       = ownerId,
                ContactUser   = user[0],
                ContactUserId = userId
            };

            contactService.Add(c);
            return(Ok(c));
        }
        public ActionResult Create([Bind(Include = "Id,Name,PhoneNumber,Birthdate,ContactTypeId")]
                                   ContactViewModel contact)
        {
            if (ModelState.IsValid)
            {
                var findContact = _contactService.Get(contact.Name);
                if (findContact == null)
                {
                    _contactService.Add(Mapper.Map <Contact>(contact));
                    return(RedirectToAction("Index"));
                }
                else
                {
                    this.ModelState.AddModelError("Name", Localization.ContactExist);
                }
            }



            contact.Name = null;
            var list = _contactTypeService.GetAll().Items;

            this.ViewBag.ContactTypeId = new SelectList(list, "Id", "Description");
            return(View(contact));
        }
Example #8
0
        public Contact Save(Contact model)
        {
            var result = model.Id > 0 ? _service.Update(model) : _service.Add(model);

            _uow.Commit();
            return(result);
        }
Example #9
0
        public IActionResult Index(Contact contact)
        {
            var contactToCreate = _contactService.CreateContact(contact.SenderName, contact.SenderEmail, contact.SenderMessage);

            _contactService.Add(contactToCreate);

            return(View(_contactViewModel));
        }
        public static int Add(this IContactService service, Action <IFieldSetter <Contact> > fieldSetter)
        {
            var setter = new TableFieldSetter <Contact>(Access.Add);

            fieldSetter(setter);

            return(service.Add(setter.XmlStruct));
        }
 public Contact Post([FromBody] Contact Contact)
 {
     if (ModelState.IsValid)
     {
         _ContactService.Add(Contact);
     }
     return(Contact);
 }
        private void AddContact(ContactCommand contactCommand)
        {
            Contact contactWithId = _contactService.Add(Mapper.Map <Contact>(contactCommand.Contact));
            ContactMobileViewModel contactViewModel = Mapper.Map <ContactMobileViewModel>(contactWithId);

            _contactMobileAppService.ObservableContacts.Add(contactViewModel);
            _contactEvents.Enqueue(new AddContactEvent(contactWithId));
        }
Example #13
0
        public ActionResult Create(
            [Bind(Include = "Name,Tell,Comment,ContactGroupName,ContactListName")] ContactViewModel contactViewModel)
        {
            if (ModelState.IsValid)
            {
                var a = contactViewModel.MapViewModelToModel();
                a.ContactListId = _contactListService.Find(r => r.Name == contactViewModel.ContactListName).Id;
                if (contactViewModel.ContactGroupName != null)
                {
                    a.ContactGroupId = _contactGroupService.Find(r => r.Name == contactViewModel.ContactGroupName).Id;
                }
                _contactService.Add(a);
                _uow.SaveChanges();
                return(Json(new { success = true }));
            }
            //ViewBag.ContactGroupNames = new SelectList(_contactGroupService.GetAll(), "Name", "Name");
            //ViewBag.ContactListNames = new SelectList(_contactListService.GetAll(), "Name", "Name");
            //پر کردن دراپ دون لیستها
            IEnumerable <DomainClasses.Models.PseezEnt.Common.ContactList> ContactLists;

            if (User.IsInRole("Admin") || User.IsInRole("ContactListAdmin"))
            {
                ContactLists = _contactListService.GetAll();
            }
            else
            {
                var userId           = _identityUserService.FindUserIdByName(User.Identity.Name);
                var userContactLists =
                    _userContactListService.GetAll(r => r.UserId == userId).Select(r => r.ContactListId);
                ContactLists = _contactListService.GetAll(r => userContactLists.Contains(r.Id));
            }
            ViewBag.ContactListNames = new SelectList(ContactLists, "Name", "Name", contactViewModel.ContactListName);

            if (ContactLists.Count() != 0)
            {
                var    firstContactListId      = ContactLists.FirstOrDefault().Id;
                string ContactGroupNamesSelect = null;
                //ContactGroupNamesSelect = null;
                foreach (
                    var contactGroupName in
                    _contactGroupService.GetAll(r => r.ContactListId == firstContactListId).Select(r => r.Name))
                {
                    if (contactGroupName == contactViewModel.ContactGroupName)
                    {
                        ContactGroupNamesSelect += "<option value=" + contactGroupName + " selected>" + contactGroupName +
                                                   "</option>";
                    }
                    else
                    {
                        ContactGroupNamesSelect += "<option value=" + contactGroupName + ">" + contactGroupName +
                                                   "</option>";
                    }
                }
                ViewBag.ContactGroupNames = ContactGroupNamesSelect;
            }
            return(PartialView("_Create", contactViewModel));
        }
Example #14
0
        public IActionResult Add(Contact contact)
        {
            var result = _contactService.Add(contact);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
Example #15
0
        public IActionResult Add(Contact contact)
        {
            var result = contactManager.Add(contact);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
Example #16
0
        public IActionResult Add(Contact contact)
        {
            var result = _contactService.Add(contact);

            if (result.Success)
            {
                return(Ok(JsonConvert.SerializeObject(result.Message)));
            }
            return(BadRequest(JsonConvert.SerializeObject(result.Message)));
        }
Example #17
0
        public bool Contact(ContactVm model)
        {
            try
            {
                MailMessage mssg = new MailMessage();
                mssg.To.Add(model.EmailDestiny);
                mssg.Subject         = "Alguien lo ha contactado";
                mssg.SubjectEncoding = Encoding.UTF8;
                mssg.Bcc.Add(model.EmailDestiny);


                string body = $"Ha sido contactado por {model.FullName}" +
                              $"<br/>" +
                              $"{model.Message}" +
                              $"<br/>" +
                              $"Contactalo por este correo {model.EmailFrom}";

                mssg.Body         = body;
                mssg.BodyEncoding = Encoding.UTF8;
                mssg.IsBodyHtml   = true;
                mssg.From         = new MailAddress("*****@*****.**");

                SmtpClient user = new SmtpClient
                {
                    Credentials = new NetworkCredential("*****@*****.**", "alonzo26"),
                    Port        = 587,
                    EnableSsl   = true,
                    Host        = "smtp.gmail.com"
                };

                try
                {
                    user.Send(mssg);
                    if (model.ApplicationUserId != null && model.FreelancerId > 0)
                    {
                        Contact contact = new Contact
                        {
                            ApplicationUserId = model.ApplicationUserId,
                            FreelancerId      = model.FreelancerId,
                            CreatedAt         = _dateTime
                        };
                        _contactService.Add(contact);
                    }
                }
                catch (Exception)
                {
                    return(false);
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public HttpResponseMessage Save(ContactForm data)
        {
            bool success = _contactService.Add(new Data.Objects.Dtos.ContactDto
            {
                From    = data.From,
                Subject = data.Subject,
                Message = data.Message
            });

            return(Request.CreateResponse <bool>(HttpStatusCode.OK, success));
        }
Example #19
0
        public IActionResult Post([FromBody] ContactRequest body)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var contact = service.Add(body.FirstName, body.Surname);

            return(Created($"/contacts/{contact.Id}", new ContactResponse(contact)));
        }
Example #20
0
        public async Task ReturnNoContent()
        {
            // Arrange
            var contact = contactService.Add("John", "Doe");

            // Act
            var response = await Client.DeleteAsync($"contacts/{contact.Id}");

            // Assert
            response.StatusCode.ShouldBe(HttpStatusCode.NoContent);
        }
Example #21
0
        public ActionResult Create(Contact contact)
        {
            if (ModelState.IsValid)
            {
                contactservice.Add(contact);
                uow.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }

            return(View(contact));
        }
        public async Task <IHttpActionResult> Add(ContactAddDto model)
        {
            bool result = await _contactService.Add(model);

            if (!result)
            {
                return(BadRequest());
            }

            return(Ok());
        }
Example #23
0
        public async Task <IActionResult> Tracking(string data, Guid adsLinkId)
        {
            var contact = new Contact
            {
                AdsLinkId = adsLinkId,
                Data      = data
            };
            await _contactService.Add(contact);

            return(Ok());
        }
        public IActionResult EmailUs(ContactViewModel contact)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            _contactService.Add(contact);
            _contactService.Save();

            return(RedirectToAction(nameof(ContactUsController.EmailSent), new { id = DateTime.Now.Ticks }));
        }
Example #25
0
 public IActionResult Post([FromBody] AddContactViewModel addContactViewModels)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     _contactService.Add(addContactViewModels);
     _contactService.Save();
     return(Ok());
     //return Created("api/PhoneBook/"+addContactViewModels.Id, addContactViewModels);
 }
        public async Task <IHttpActionResult> Post(ContactVM vmContact)
        {
            var Id = await _contactService.Add(vmContact);

            if (Id > 0)
            {
                return(Ok(Id));
            }

            return(BadRequest("Some error occured while creating record"));
        }
Example #27
0
        public async Task <IActionResult> Create([FromBody] Contact createContact)
        {
            if (createContact is null)
            {
                return(BadRequest());
            }

            var stat = await _contactService.Add(createContact);

            return(Ok(stat));
        }
 public IActionResult Post([FromBody] Contact contact)
 {
     if (ModelState.IsValid)
     {
         var result = contactService.Add(contact);
         return(Created($"/api/Contact/{result}", "باموفقیت ثبت شد"));
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }
        public ActionResult Contact(Contact contact)
        {
            var userId = Convert.ToInt32(Session["Id"]);
            var user   = _userService.GetById(userId);

            if (Session["Id"] != null)
            {
                contact.UserId      = userId;
                contact.UserName    = user.Data.FirstName;
                contact.UserEmail   = user.Data.Email;
                contact.MessageDate = DateTime.Now;
                _contactService.Add(contact);
            }
            else
            {
                contact.MessageDate = DateTime.Now;
                _contactService.Add(contact);
            }

            return(RedirectToAction("Contact"));
        }
Example #30
0
        public IActionResult SaveEntity(ContactDetailViewModel contactVm)
        {
            try
            {
                if (contactVm.Id == 0)
                {
                    var errorBySlideName = "Tên slide đã tồn tại";
                    if (_contactService.ValidateAddContactDetailName(contactVm))
                    {
                        ModelState.AddModelError("",
                                                 errorBySlideName);
                    }

                    if (!ModelState.IsValid)
                    {
                        return(BadRequest(ModelState.Select(x => x.Value.Errors).FirstOrDefault(y => y.Count > 0)?.First()
                                          .ErrorMessage));
                    }
                    _contactService.Add(contactVm);
                }
                else
                {
                    var errorBySlideName = "Tên slide đã tồn tại";
                    if (_contactService.ValidateUpdateContactDetailName(contactVm))
                    {
                        ModelState.AddModelError("",
                                                 errorBySlideName);
                    }

                    if (!ModelState.IsValid)
                    {
                        return(BadRequest(ModelState.Select(x => x.Value.Errors).FirstOrDefault(y => y.Count > 0)?.First()
                                          .ErrorMessage));
                    }

                    _contactService.Update(contactVm);
                }

                //if (!ModelState.IsValid)
                //{
                //    IEnumerable<ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);
                //    return new BadRequestObjectResult(allErrors);
                //}

                _contactService.Save();
                return(new OkObjectResult(contactVm));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }