Example #1
0
        public async Task Task_AddNewContactAsync_AddNewContact_Valid_Data_ReturningSuccessMessage()
        {
            // arrange phase
            var            contactInfo    = _contactInfo.FirstOrDefault();
            ContactInfoDTO contactInfoDTO = _mapper.Map <ContactInfoDTO>(contactInfo);

            _repository.Setup(t => t.AddTAsync(contactInfo)).ReturnsAsync(1);

            // mock returing created record
            _repository.Setup(t => t.GetOneByAsync(t => t.Id == contactInfo.Id)).ReturnsAsync(contactInfo);

            // processing phase
            var controller = new ContactController(_repository.Object, _mapper);

            var result = await controller.AddNewContactAsync(contactInfo);

            // assert phase

            var objResult    = Assert.IsType <CreatedResult>(result.Result);
            var statusResult = objResult.StatusCode;
            var actualResult = objResult.Value as ContactInfoDTO;

            //assert result
            Assert.NotNull(result);

            //assert statusCode
            Assert.Equal(201, statusResult);

            //assert validate
            actualResult.Should().BeEquivalentTo(contactInfoDTO, t => t.ComparingByMembers <ContactInfoDTO>());
        }
    public bool merge(ContactInfoDTO entity)
    {
        try
        {
            var addObj = (from p in ctx.ContactInfos
                       where p.userName == @entity.userName && p.contactType == @entity.contactType
                       select p).Single();

            model.ContactInfo obj = (ContactInfo)addObj;

            /*Update*/
            obj.userName = entity.userName;
            obj.contactType = entity.contactType;
            obj.data = entity.data;

            ctx.SubmitChanges();
            return true;
        }
        catch (Exception e)
        {
            model.Log log = new Log();
            log.message = "ContactInfo Merge: " + " ["+entity.userName+" , "+entity.contactType+"] " + e.Message;

            ctx.Dispose();
            ctx = new ModelDataContext();
            ctx.SubmitChanges();

            return false;
        }
    }
Example #3
0
        public async Task <IActionResult> PostContactInformation(string session, [FromBody] ContactInfoDTO data)
        {
            var           vehicle  = _entryService.GetVehicle(int.Parse(session));
            var           dateTime = _entryService.GetDateTime(int.Parse(session));
            List <string> services = new List <string>();

            var allServices = _serviceRepository.Get();
            var ids         = _entryService.GetServiceNeeds(int.Parse(session));

            foreach (var id in ids)
            {
                services.Add(allServices.Find(el => el.ServiceId == id).Name);
            }
            var fromAddress = new MailAddress("*****@*****.**", "CarService"); //email

            var toAddress = new MailAddress(data.Email, "CarService");
            //const string fromPassword = "******"; //Password
            const string fromPassword = "******"; //Password
            //const string fromPassword = "******"; //Password
            string subject = "Your appointment has been scheduled";
            string body    = "<h2> Hello, " + data.FirstName + " " + data.LastName + "<h2>"
                             + "<p>" + "Your appointment has been scheduled" + "</p>"
                             + "<h3>Date and Time: </h3>"
                             + "<p>" + dateTime + "</p>"
                             + "<h3>Vehicle: </h3>"
                             + "<p>" + $"{vehicle.Year} {vehicle.Make} {vehicle.Model}" + "</p>"
                             + "<h3>" + "Services:" + "</h3>"
                             + "<ul>";

            foreach (var service in services)
            {
                body += "<li>" + service + "</li>";
            }
            body += "</ul>";

            var smtp = new SmtpClient
            {
                Host           = "smtp.gmail.com",
                Port           = 587,
                EnableSsl      = true,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                //UseDefaultCredentials = false,
                Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
            };

            using (var message = new MailMessage(fromAddress, toAddress)
            {
                Subject = subject,
                Body = body,
                IsBodyHtml = true
            })
            {
                smtp.Send(message);
            }
            //_entryService.RemoveSession(int.Parse(session));
            return(Ok(new { dateTime = dateTime }));
        }
    public ContactInfoDTO find(string userName, string contactType)
    {
        var obj = (from p in ctx.ContactInfos
                   where p.userName == @userName && p.contactType == @contactType
                   select p).Single();

        ContactInfoDTO add = new ContactInfoDTO();
        add.userName = obj.userName;
        add.contactType = obj.contactType;
        add.data = obj.data;

        return add;
    }
Example #5
0
        public async Task <ActionResult <ContactInfoDTO> > UpdateContactAsync([FromRoute] string id, [FromBody] ContactInfo updateContact)
        {
            updateContact.Id = id;
            int result = await _genericRepository.UpdateTAsync(updateContact);

            if (result == 0)
            {
                return(NotFound("No Contact Updated"));
            }

            ContactInfoDTO contactInfoDTO = _mapper.Map <ContactInfoDTO>(updateContact);

            return(Ok(contactInfoDTO));
        }
    public ContactInfoDTO find(string userName, string contactType)
    {
        ContactInfoDTO info = new ContactInfoDTO();
        SqlConnection oConn = new SqlConnection();
        SqlCommand sqlCmd = null;

        try
        {
            oConn.ConnectionString = ConfigurationManager.AppSettings["conn"];
            oConn.Open();

            sqlCmd = oConn.CreateCommand();
            sqlCmd.CommandType = CommandType.Text;
            sqlCmd.CommandText = "select * from ContactInfo where userName = '******' AND contactType = '" + contactType + "'";

            SqlDataReader rdr = sqlCmd.ExecuteReader();

            if (rdr.HasRows)
            {
                while (rdr.Read())
                {
                    info.userName = rdr["userName"].ToString();
                    info.contactType = rdr["contactType"].ToString();
                    info.data = rdr["data"].ToString();
                }
            }

        }
        catch
        { }
        finally
        {
            if (sqlCmd != null)
            {
                sqlCmd = null;
            }
            if (oConn != null)
            {
                if (oConn.State.Equals(ConnectionState.Open))
                {
                    oConn.Close();
                }
                oConn = null;
            }
        }
        return info;
    }
    public List<ContactInfoDTO> findAll()
    {
        var objs = (from p in ctx.ContactInfos
                    select p);
        ContactInfoDTO add = null;
        List<ContactInfoDTO> addList = new List<ContactInfoDTO>();
        foreach (ContactInfo obj in objs)
        {
            add = new ContactInfoDTO();
            add.userName = obj.userName;
            add.contactType = obj.contactType;
            add.data = obj.data;

            addList.Add(add);
        }
        return addList;
    }
        public void ContactInfo_Test()
        {
            /*Context*/
            ContactInfoDAO contactInfo_context = new ContactInfoDAO();
            AccountDAO acc_context = new AccountDAO();
            /*Insert*/
            AccountDTO acc = new AccountDTO();
            acc.userName = "******";
            acc.password = "******";
            acc.accountType = "administrator";
            acc.status = "active";

            acc_context.presist(acc);

            ContactInfoDTO contact = new ContactInfoDTO();
            contact.userName = "******";
            contact.contactType = "skype";
            contact.data = "skippy";

            contactInfo_context.presist(contact);

            bool expected = true; // TODO: Initialize to an appropriate value
            bool actual;
            actual = contactInfo_context.isFound("griddy", "skype");
            Assert.AreEqual(expected, actual);

            /*Update*/
            contact.data = "Gready";
            contactInfo_context.merge(contact);

            string expectedUpdate = "Gready";
            ContactInfoDTO contUpd = contactInfo_context.find("griddy", "skype");
            Assert.AreEqual(expectedUpdate, contUpd.data);

            /*Delete*/
            contactInfo_context.removeByUserId("griddy", "skype");

            bool expectedDelete = false;
            bool actualDelete = contactInfo_context.isFound("griddy", "skype");
            Assert.AreEqual(expectedDelete, actualDelete);

            acc_context.removeByUserId("griddy");
        }
Example #9
0
        public async Task <ActionResult <ContactInfoDTO> > AddNewContactAsync([FromBody] ContactInfo newContact)
        {
            if (newContact == null)
            {
                return(NotFound("Input object cannot be null"));
            }
            newContact.Id = Guid.NewGuid().ToString();
            int created = await _genericRepository.AddTAsync(newContact);

            if (created == 0)
            {
                return(NotFound("No New Contact created"));
            }

            var newRecord = await _genericRepository.GetOneByAsync(t => t.Id == newContact.Id);

            ContactInfoDTO contactInfoDTO = _mapper.Map <ContactInfoDTO>(newRecord);

            return(Created("New Contact Created", contactInfoDTO));
        }
        protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
        {
            // Determine the currently logged on user's UserId
            //MembershipUser currentUser = Membership.GetUser();
            //Guid currentUserId = (Guid)currentUser.ProviderUserKey;

            //Create user in Account table
            DAO_Account_Interface acc_ctx = new AccountDAO();
            AccountDTO newAccount = new AccountDTO();

            newAccount.userName = CreateUserWizard1.UserName.ToLower();
            newAccount.password = "******";
            newAccount.status = "active";
            newAccount.accountType = "user";
            acc_ctx.presist(newAccount);

            //Add User Email to COntact Info
            DAO_ContactInfo_Interface info_ctx = new ContactInfoDAO();
            ContactInfoDTO mail_info = new ContactInfoDTO();
            mail_info.userName = newAccount.userName;
            mail_info.contactType = "e-mail";
            mail_info.data = CreateUserWizard1.Email;
            info_ctx.presist(mail_info);

            //Add User information to User Table
            DAO_User_Interface user_ctx = new UserDAO();
            UserDTO user_info = new UserDTO();
            user_info.userName = newAccount.userName;
            user_info.id = txtID.Text;
            user_info.fullName = txtName.Text;
            user_info.surname = txtSurname.Text;
            user_info.nickName = txtNickname.Text;
            user_info.idType = RadioIdType.SelectedValue;
            user_info.race = RadioRace.SelectedValue;
            user_info.gender = RadioGender.SelectedValue;
            user_ctx.presist(user_info);

            Roles.AddUserToRole(newAccount.userName, "User");
        }
 public void setContactDto(ContactInfoDTO contactInformationDto)
 {
     view.setContactType(contactInformationDto.contactType);
     view.setData(contactInformationDto.data);
     //view.setUsername(contactInformationDto.userName);
 }
 public ContactInfoDTO getContactInformationDto()
 {
     ContactInfoDTO contactInfoDto = new ContactInfoDTO();
     contactInfoDto.userName = view.getUsername();
     contactInfoDto.contactType = view.getContactType();
     contactInfoDto.data = view.getData();
     return contactInfoDto;
 }
 public bool remove(ContactInfoDTO entity)
 {
     return this.removeByUserId(entity.userName, entity.contactType);
 }
    public bool presist(ContactInfoDTO entity)
    {
        bool success = false;
        SqlConnection oConn = new SqlConnection();
        SqlCommand sqlCmd = null;

        try
        {
            oConn.ConnectionString = ConfigurationManager.AppSettings["conn"];
            oConn.Open();

            sqlCmd = oConn.CreateCommand();
            sqlCmd.CommandType = CommandType.StoredProcedure;
            sqlCmd.CommandText = "insertContactInfo";
            sqlCmd.Parameters.Add(new SqlParameter("userName", entity.userName));
            sqlCmd.Parameters.Add(new SqlParameter("contactType", entity.contactType));
            sqlCmd.Parameters.Add(new SqlParameter("data", entity.data));

            SqlDataReader rdr = sqlCmd.ExecuteReader();
            if (rdr.HasRows)
            {
                while (rdr.Read())
                { } //Read all
            }
            rdr.Close();

            if (rdr.RecordsAffected > 0)
                success = true;
        }
        catch { }
        finally
        {
            if (sqlCmd != null)
            {
                sqlCmd = null;
            }
            if (oConn != null)
            {
                if (oConn.State.Equals(ConnectionState.Open))
                {
                    oConn.Close();
                }
                oConn = null;
            }
        }
        return success;
    }
    public bool presist(ContactInfoDTO entity)
    {
        try
        {
            model.ContactInfo obj = new ContactInfo();
            obj.userName = entity.userName;
            obj.contactType = entity.contactType;
            obj.data = entity.data;

            ctx.ContactInfos.InsertOnSubmit(obj);
            ctx.SubmitChanges();
            return true;
        }
        catch (Exception)
        {
            ctx.Dispose();
            ctx = new ModelDataContext();
            return false;
        }
    }