Ejemplo n.º 1
0
    public bool merge(InboxDTO entity)
    {
        try
        {
            var addObj = (from p in ctx.Inboxes
                       where p.userName == @entity.userName && p.messageId == @entity.messageId
                       select p).Single();

            model.Inbox obj = (Inbox)addObj;

            /*Update*/
            obj.userName = entity.userName;
            obj.messageId = entity.messageId;
            obj.date = entity.date;
            obj.unread = entity.unread;
            obj.message = entity.message;

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

            ctx.Dispose();
            ctx = new ModelDataContext();
            return false;
        }
    }
        protected void vacRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            String element = e.CommandName.ToString();
             string userName = (string)Session["username"];

             ApplicationDAO app_ctx = new ApplicationDAO();
             ApplicationDTO obj = new ApplicationDTO();

             if(!app_ctx.isFound(userName,element) )
             {
                 obj.userName = userName;
                 obj.vacancyNumber = element;
                 obj.status = ApplicationStatus.APPLIED.ToString();
                 obj.appDate = DateTime.Now;
                 app_ctx.presist(obj);

                 InboxDTO inbox = new InboxDTO();
                 inbox.date = DateTime.Now;
                 inbox.message = "You have successfully applied for vacancy " + element;
                 inbox.status = ApplicationStatus.APPLIED.ToString();
                 inbox.unread = "unread";
                 inbox.userName = userName;
                 inbox.vacancyNumber = element;

                 InboxDAO dao = new InboxDAO();
                 dao.presist(inbox);

                 Response.Redirect("~/Inbox/InboxMessage.aspx");
             }
        }
Ejemplo n.º 3
0
    public InboxDTO find(string userName, string vacancyNumber)
    {
        InboxDTO info = new InboxDTO();
        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 Inbox where userName = '******' AND vacancyNumber = " + vacancyNumber;

            SqlDataReader rdr = sqlCmd.ExecuteReader();

            if (rdr.HasRows)
            {
                while (rdr.Read())
                {
                    info.userName = rdr["userName"].ToString();
                    info.vacancyNumber = rdr["vacancyNumber"].ToString();
                    info.date = DateTime.Parse(rdr["date"].ToString() );
                    info.unread = rdr["unread"].ToString();
                    info.message = rdr["message"].ToString();
                    info.status = rdr["status"].ToString();

                }
            }

        }
        catch
        { }
        finally
        {
            if (sqlCmd != null)
            {
                sqlCmd = null;
            }
            if (oConn != null)
            {
                if (oConn.State.Equals(ConnectionState.Open))
                {
                    oConn.Close();
                }
                oConn = null;
            }
        }
        return info;
    }
Ejemplo n.º 4
0
    public InboxDTO find(string userName, int messageId)
    {
        var obj = (from p in ctx.Inboxes
                   where p.userName == @userName && p.messageId == @messageId
                   select p).Single();

        InboxDTO add = new InboxDTO();
        add.userName = obj.userName;
        add.messageId = obj.messageId;
        add.date = obj.date;
        add.unread = obj.unread;
        add.message = obj.message;

        return add;
    }
Ejemplo n.º 5
0
        public IHttpActionResult Create([FromBody] InboxDTO inboxDTO)
        {
            try
            {
                var inboxBusiness = new InboxBusiness();

                var inbox = inboxBusiness.Create(inboxDTO);

                return(Ok(inbox));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Ejemplo n.º 6
0
        public void InboxDAOConstructorTest()
        {
            /*Context*/
            InboxDAO inbox_context = new InboxDAO();
            AccountDAO account_context = new AccountDAO();

            /*Insert*/
            AccountDTO account = new AccountDTO();
            account.userName = "******";
            account.status = "active";
            account.password = "******";
            account.accountType = "admin";

            account_context.presist(account);

            InboxDTO inbox = new InboxDTO();
            inbox.date = new DateTime(2012, 9, 30);
            inbox.message = "success";
            inbox.vacancyNumber = "1";
            inbox.unread = "read";
            inbox.userName = "******";
            inbox.status = "applied";

            inbox_context.presist(inbox);

            bool expected = true;
            bool actual;
            actual = inbox_context.isFound("john", "1");
            Assert.AreEqual(expected, actual);

            /*Update*/
            inbox.unread = "not read";
            inbox_context.merge(inbox);
            string expectedUpdate = "not read";
            InboxDTO contUpd = inbox_context.find("john", "1");
            Assert.AreEqual(expectedUpdate, contUpd.unread);

            /*Delete*/
            inbox_context.removeByUserId("john", "1");
            bool expectedDelete = false;
            bool actualDelete = inbox_context.isFound("john", "1");
            Assert.AreEqual(expectedDelete, actualDelete);

            account_context.removeByUserId("john");
        }
Ejemplo n.º 7
0
    public List<InboxDTO> findAll()
    {
        var objs = (from p in ctx.Inboxes
                    select p);
        InboxDTO add = null;
        List<InboxDTO> addList = new List<InboxDTO>();
        foreach (Inbox obj in objs)
        {
            add = new InboxDTO();
            add.userName = obj.userName;
            add.messageId = obj.messageId;
            add.date = obj.date;
            add.unread = obj.unread;
            add.message = obj.message;

            addList.Add(add);
        }
        return addList;
    }
Ejemplo n.º 8
0
 public bool remove(InboxDTO entity)
 {
     return this.removeByUserId(entity.userName, entity.vacancyNumber);
 }
Ejemplo n.º 9
0
    public bool presist(InboxDTO 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 = "insertInbox";
            sqlCmd.Parameters.Add(new SqlParameter("userName", entity.userName));
            sqlCmd.Parameters.Add(new SqlParameter("vacancyNumber", entity.vacancyNumber));
            sqlCmd.Parameters.Add(new SqlParameter("date", entity.date));
            sqlCmd.Parameters.Add(new SqlParameter("unread", entity.unread));
            sqlCmd.Parameters.Add(new SqlParameter("message", entity.message));
            sqlCmd.Parameters.Add(new SqlParameter("status", entity.status));

            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;
    }
Ejemplo n.º 10
0
 public bool remove(InboxDTO entity)
 {
     return this.removeByUserId(entity.userName,entity.messageId);
 }
Ejemplo n.º 11
0
    public bool presist(InboxDTO entity)
    {
        try
        {
            model.Inbox obj = new Inbox();
            obj.userName = entity.userName;
            obj.messageId = entity.messageId;
            obj.date = entity.date;
            obj.unread = entity.unread;
            obj.message = entity.message;

            ctx.Inboxes.InsertOnSubmit(obj);
            ctx.SubmitChanges();
            return true;
        }
        catch (Exception)
        {
            ctx.Dispose();
            ctx = new ModelDataContext();
            return false;
        }
    }
Ejemplo n.º 12
0
        public void inboxMessagesTest()
        {
            InboxService inboxService = new InboxServiceImpl();

            /*Context*/
            InboxDAO inbox_context = new InboxDAO();
            AccountDAO account_context = new AccountDAO();

            /*Insert*/
            AccountDTO account = new AccountDTO();
            account.userName = "******";
            account.status = "active";
            account.password = "******";
            account.accountType = "admin";

            account_context.presist(account);

            InboxDTO inbox = new InboxDTO();
            inbox.date = new DateTime(2012, 9, 30);
            inbox.message = "success";
            inbox.messageId = 1;
            inbox.unread = "unread";
            inbox.userName = "******";

            inbox_context.presist(inbox);

            bool expected = true;
            bool actual;
            actual = inbox_context.isFound("griddy", 1);
            Assert.AreEqual(expected, actual);

            //Test getInboxMessagesByDate method
            Assert.AreEqual(true, inboxService.hasUnreadMessage("griddy"));

            //Test getInboxMessagesByMessage method
            int inboxMessageNumber = inboxService.getNumberOfInboxMessages("griddy");
            Assert.AreEqual(1, inboxMessageNumber);

            //Test setMessagesRead method
            inboxService.setMessagesRead("griddy", 1);
            InboxMessageSearchService inboxSearchService = new InboxMessageSearchServiceImpl();
            List<InboxDTO> inboxDtoList = inboxSearchService.getInboxMessagesByUsername("griddy");

            Assert.AreEqual("read", inboxDtoList[0].unread);
            inboxDtoList.RemoveRange(0, inboxDtoList.Count);
            inboxDtoList = null;
            inbox = null;

            /*Delete*/
            inbox_context = new InboxDAO();
            inbox_context.removeByUserId("griddy", 1);
            bool expectedDelete = false;
            bool actualDelete = inbox_context.isFound("griddy", 1);
            Assert.AreEqual(expectedDelete, actualDelete);

            account_context.removeByUserId("griddy");
        }