Example #1
0
        public IUserDTO UpdateProfile(IUserDTO userDTO)
        {
            IUserDTO retVal = null;

            try
            {
                using (EmployeePortal2017Entities portal = new EmployeePortal2017Entities())
                {
                    var user = portal.Users.Include("Employee").Where(u => u.EmployeeId == userDTO.EmployeeDTO.EmployeeId).SingleOrDefault();
                    if (user != null)
                    {
                        userDTO.UserId = user.UserId;
                        EntityConverter.FillEntityFromDTO(userDTO, user);
                        EntityConverter.FillEntityFromDTO(userDTO.EmployeeDTO, user.Employee);

                        portal.SaveChanges();
                        retVal = userDTO;
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException(ex.Message);
            }
            return(retVal);
        }
Example #2
0
        public IUserDTO Login(string username, string password)
        {
            IUserDTO userDTO = null;

            try
            {
                using (EmployeePortal2017Entities portal = new EmployeePortal2017Entities())
                {
                    User userEntity = new User();
                    userEntity.Employee = new Employee();
                    IUserDTO user = (IUserDTO)DTOFactory.Instance.Create(DTOType.UserDTO);
                    user.EmployeeDTO = (IEmployeeDTO)DTOFactory.Instance.Create(DTOType.EmployeeDTO);
                    user             = GetUserByEmailId(username);

                    EntityConverter.FillEntityFromDTO(user, userEntity);
                    EntityConverter.FillEntityFromDTO(user.EmployeeDTO, userEntity.Employee);
                    if (user != null)
                    {
                        userDTO = (IUserDTO)DTOFactory.Instance.Create(DTOType.UserDTO);
                        EntityConverter.FillDTOFromEntity(userEntity, userDTO);
                        userDTO.EmployeeDTO = (IEmployeeDTO)DTOFactory.Instance.Create(DTOType.EmployeeDTO);

                        EntityConverter.FillDTOFromEntity(userEntity.Employee, userDTO.EmployeeDTO);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException(ex.Message);
            }
            return(userDTO);
        }
        public IHttpActionResult Register([FromBody] User user)
        {
            user.Created = DateTime.Now;

            IUserDTO userDTO = (IUserDTO)DTOFactory.Instance.Create(DTOType.UserDTO);

            EntityConverter.FillDTOFromEntity(user, userDTO);

            IUserFacade userFacade            = (IUserFacade)FacadeFactory.Instance.Create(FacadeType.UserFacade);
            OperationResult <IUserDTO> result = userFacade.Register(userDTO);

            if (result.ResultType == OperationResultType.Failure)
            {
                string failed = JsonConvert.SerializeObject(new { success = false, data = result.Message });
                return(BadRequest(failed));
            }

            if (result.IsValid())
            {
                EntityConverter.FillEntityFromDTO(result.Data, user);
                string success = JsonConvert.SerializeObject(new { success = true, data = user });
                return(Ok(success));
            }

            string jsonObj = JsonConvert.SerializeObject(new { success = false, data = result.Message });

            return(BadRequest(jsonObj));
        }
Example #4
0
        /// <summary>
        /// Method to create tag
        /// </summary>
        /// <param name=""></param>
        public bool Create(List <ITagsDTO> listOfTags, int questionId)
        {
            using (var context = new BufferOverflowDBEntities())
            {
                foreach (var tags in listOfTags)
                {
                    var isExist = context.Tags.SingleOrDefault(t => t.Tag == tags.Tag);
                    if (isExist == null)
                    {
                        Tags tagEntity = new Tags();
                        EntityConverter.FillEntityFromDTO(tags, tagEntity);
                        isExist = context.Tags.Add(tagEntity);
                        context.SaveChanges();
                    }
                    TagRelation tagRelationEntity = context.TagRelation.SingleOrDefault(t => t.TagId == isExist.Id && t.QuestionId == questionId);
                    if (tagRelationEntity == null)
                    {
                        tagRelationEntity            = new TagRelation();
                        tagRelationEntity.QuestionId = questionId;
                        tagRelationEntity.TagId      = isExist.Id;
                        context.TagRelation.Add(tagRelationEntity);
                        context.SaveChanges();
                    }
                }

                return(true);
            }
        }
        /// <summary>
        /// Create a new entry in the notice table , if inserted successfully
        ///           a.Yes – return the inserted NoticeDTO
        ///           b.No – return null
        /// </summary>
        /// <param name="noticeDTO"></param>
        /// <returns></returns>
        public INoticeDTO CreateNotice(INoticeDTO noticeDTO)
        {
            INoticeDTO createNoticeRetval = null;

            try
            {
                using (EmployeePortal2017Entities portal = new EmployeePortal2017Entities())
                {
                    noticeDTO.IsActive = true;
                    Notice notice = new Notice();
                    EntityConverter.FillEntityFromDTO(noticeDTO, notice);
                    portal.Notices.Add(notice);
                    if (portal.SaveChanges() > 0)
                    {
                        noticeDTO.NoticeId = notice.NoticeId;
                        createNoticeRetval = noticeDTO;
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException(ex.Message);
            }
            return(createNoticeRetval);
        }
Example #6
0
        public IHttpActionResult Create([FromBody] Answers answer)
        {
            answer.Created = DateTime.Now;
            IAnswerDTO answerDTO = (IAnswerDTO)DTOFactory.Instance.Create(DTOType.AnswerDTO);

            EntityConverter.FillDTOFromEntity(answer, answerDTO);

            IAnswerFacade answerFacade          = (IAnswerFacade)FacadeFactory.Instance.Create(FacadeType.AnswerFacade);
            OperationResult <IAnswerDTO> result = answerFacade.Create(answerDTO);

            if (result.ResultType == OperationResultType.Failure)
            {
                string failed = JsonConvert.SerializeObject(new { success = false, data = result.Message });
                return(BadRequest(failed));
            }

            if (result.IsValid())
            {
                //Answers answerEntity = new Answers();
                EntityConverter.FillEntityFromDTO(result.Data, answer);
                string success = JsonConvert.SerializeObject(new { success = true, data = answer });
                return(Ok(success));
            }

            string jsonObj = JsonConvert.SerializeObject(new { success = false, data = result.Message });

            return(BadRequest(jsonObj));
        }
        public IHttpActionResult Create([FromBody] Questions data)
        {
            IQuestionDTO dataDTO = (IQuestionDTO)DTOFactory.Instance.Create(DTOType.QuestionDTO);

            EntityConverter.FillDTOFromEntity(data, dataDTO);
            dataDTO.Created = DateTime.Now;


            IQuestionFacade questionFacade        = (IQuestionFacade)FacadeFactory.Instance.Create(FacadeType.QuestionFacade);
            OperationResult <IQuestionDTO> result = questionFacade.Create(dataDTO);

            if (result.ResultType == OperationResultType.Failure)
            {
                string failed = JsonConvert.SerializeObject(new { success = false, data = result.Message });
                return(BadRequest(failed));
            }

            if (result.IsValid())
            {
                Questions question = new Questions();
                EntityConverter.FillEntityFromDTO(result.Data, question);
                string success = JsonConvert.SerializeObject(new { success = true, data = question });
                return(Ok(success));
            }

            string jsonObj = JsonConvert.SerializeObject(new { success = false, data = result.Message });

            return(BadRequest(jsonObj));
        }
Example #8
0
        public IHttpActionResult Delete(int id)
        {
            IAnswerDTO answer = (IAnswerDTO)DTOFactory.Instance.Create(DTOType.AnswerDTO);

            answer.Id = id;
            IAnswerFacade answerFacade          = (IAnswerFacade)FacadeFactory.Instance.Create(FacadeType.AnswerFacade);
            OperationResult <IAnswerDTO> result = answerFacade.Delete(answer);

            if (result.ResultType == OperationResultType.Failure)
            {
                string failed = JsonConvert.SerializeObject(new { success = false, data = result.Message });
                return(BadRequest(failed));
            }

            if (result.IsValid())
            {
                Answers answerModel = new Answers();
                EntityConverter.FillEntityFromDTO(result.Data, answerModel);
                string success = JsonConvert.SerializeObject(new { success = true, data = answerModel });
                return(Ok(success));
            }
            string jsonObj = JsonConvert.SerializeObject(new { success = false, data = result.Message });

            return(BadRequest(jsonObj));
        }
Example #9
0
        public IHttpActionResult CreateVote([FromBody] Votes vote)
        {
            IVoteDTO votesDTO = (IVoteDTO)DTOFactory.Instance.Create(DTOType.VoteDTO);

            EntityConverter.FillDTOFromEntity(vote, votesDTO);
            IAnswerFacade answerFacade        = (IAnswerFacade)FacadeFactory.Instance.Create(FacadeType.AnswerFacade);
            OperationResult <IDataDTO> result = answerFacade.CreateVote(votesDTO);

            if (result.ResultType == OperationResultType.Failure)
            {
                string failed = JsonConvert.SerializeObject(new { success = false, data = result.Message });
                return(BadRequest(failed));
            }

            if (result.IsValid())
            {
                Data dataModel = new Data();
                EntityConverter.FillEntityFromDTO(result.Data.VoteDetail, dataModel.VoteDetail);
                dataModel.TotalVote = result.Data.TotalVote;
                string success = JsonConvert.SerializeObject(new { success = true, data = dataModel });
                return(Ok(success));
            }
            string jsonObj = JsonConvert.SerializeObject(new { success = false, data = result.Message });

            return(BadRequest(jsonObj));
        }
Example #10
0
        /// <summary>
        /// Updates a survey
        /// </summary>
        /// <param name="surveyDto"></param>
        /// <returns></returns>
        public ISurveyDTO UpdateSurvey(ISurveyDTO surveyDto)
        {
            try
            {
                if (surveyDto != null)
                {
                    using (var dbContext = new SSEntities())
                    {
                        var surveyEntity = (from qs in dbContext.Surveys
                                            where qs.Id == surveyDto.Id
                                            select qs).Single();

                        if (surveyEntity != null)
                        {
                            EntityConverter.FillEntityFromDTO(surveyDto, surveyEntity);
                        }

                        if (dbContext.SaveChanges() > 0)
                        {
                            surveyDto.Id = surveyEntity.Id;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException("Error while updating the Survey.", ex);
            }
            return(surveyDto);
        }
Example #11
0
 /// <summary>
 /// Creates a survey
 /// </summary>
 /// <param name="surveyDto"></param>
 /// <returns></returns>
 public ISurveyDTO CreateSurvey(ISurveyDTO surveyDTO)
 {
     try
     {
         if (surveyDTO != null)
         {
             using (var context = new SSEntities())
             {
                 var surveyEntity = new Survey();
                 EntityConverter.FillEntityFromDTO(surveyDTO, surveyEntity);
                 context.Surveys.Add(surveyEntity);
                 if (context.SaveChanges() > 0)
                 {
                     surveyDTO.Id = surveyEntity.Id;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         ExceptionManager.HandleException(ex);
         throw new DACException("Error while creating the Survey.", ex);
     }
     return(surveyDTO);
 }
Example #12
0
        public IUsersDTO CreateUser(IUsersDTO usersDTO)
        {
            IUsersDTO createUserRetval = null;

            try
            {
                using (EmployeePortalEntities context = new EmployeePortalEntities())
                {
                    Employee employee = new Employee();
                    EntityConverter.FillEntityFromDTO(usersDTO.Employee, employee);
                    context.Employees.Add(employee);

                    User user = new User();
                    user.EmployeeId = employee.EmployeeId;
                    EntityConverter.FillEntityFromDTO(usersDTO, user);
                    context.Users.Add(user);


                    // user.UserId = usersDTO.UserId;
                    //employee.EmployeeId = usersDTO.EmployeesDTO.EmployeeId;
                    context.SaveChanges();
                    createUserRetval = usersDTO;
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException(ex.Message);
            }
            return(createUserRetval);
        }
Example #13
0
        public IUserDTO CreateUser(IUserDTO userDTO)
        {
            IUserDTO retVal = null;

            try
            {
                using (CasinoPortalEntities context = new CasinoPortalEntities())
                {
                    userDTO.BlockedAmount  = 0;
                    userDTO.AccountBalance = 500;
                    userDTO.UniqueUserId   = RandomString(8);
                    User user = new User();
                    EntityConverter.FillEntityFromDTO(userDTO, user);
                    context.Users.Add(user);
                    context.SaveChanges();
                    userDTO.UserID = user.UserID;
                    retVal         = userDTO;
                }
            }

            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException(ex.Message);
            }
            return(retVal);
        }
        public IHttpActionResult GetProfile(int id)
        {
            IUserDTO userDTO = (IUserDTO)DTOFactory.Instance.Create(DTOType.UserDTO);

            userDTO.Id = id;
            IUserFacade userFacade            = (IUserFacade)FacadeFactory.Instance.Create(FacadeType.UserFacade);
            OperationResult <IUserDTO> result = userFacade.GetProfile(userDTO);

            if (result.ResultType == OperationResultType.Failure)
            {
                string failed = JsonConvert.SerializeObject(new { success = false, data = result.Message });
                return(BadRequest(failed));
            }

            if (result.IsValid())
            {
                User user = new User();
                EntityConverter.FillEntityFromDTO(result.Data, user);
                string success = JsonConvert.SerializeObject(new { success = true, data = user });
                return(Ok(success));
            }

            string jsonObj = JsonConvert.SerializeObject(new { success = false, data = result.Message });

            return(BadRequest(jsonObj));
        }
        /// <summary>
        /// Update the notice table accordingly, Is Updated successfully
        ///            a.Yes – return the updated NoticeDTO
        ///            b.No – return Null
        /// </summary>
        /// <param name="noticeDTO"></param>
        /// <returns></returns>
        public INoticeDTO UpdateNotice(INoticeDTO noticeDTO)
        {
            INoticeDTO retVal = null;

            try
            {
                using (EmployeePortal2017Entities portal = new EmployeePortal2017Entities())
                {
                    var notice = portal.Notices.Where(n => n.NoticeId == noticeDTO.NoticeId).SingleOrDefault <Notice>();
                    if (notice != null)
                    {
                        noticeDTO.IsActive = notice.IsActive;
                        EntityConverter.FillEntityFromDTO(noticeDTO, notice);
                        if (portal.SaveChanges() > 0)
                        {
                            retVal = noticeDTO;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException(ex.Message);
            }

            return(retVal);
        }
        /// <summary>
        /// Update the issue table (changes only in Issue table , no changes in Issue history table)
        ///             a.Yes – return the updated IssueDTO
        ///             b.No – return Null
        /// </summary>
        /// <param name="issueDTO"></param>
        /// <returns></returns>
        public IIssueDTO UpdateIssue(IIssueDTO issueDTO)
        {
            IIssueDTO updateIssueRetVal = null;

            try
            {
                using (EmployeePortal2017Entities portal = new EmployeePortal2017Entities())
                {
                    Issue issue = portal.Issues.Where(i => i.IssueId == issueDTO.IssueId).SingleOrDefault();
                    if (issue != null)
                    {
                        issueDTO.IsActive = true;
                        EntityConverter.FillEntityFromDTO(issueDTO, issue);
                        if (portal.SaveChanges() > 0)
                        {
                            updateIssueRetVal = issueDTO;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException(ex.Message);
            }
            return(updateIssueRetVal);
        }
Example #17
0
        public IIssuesDTO CreateIssue(IIssuesDTO issuesDTO)
        {
            IIssuesDTO createIssueRetval = null;

            try
            {
                using (EmployeePortalEntities context = new EmployeePortalEntities())
                {
                    Issue issue = new Issue();
                    issuesDTO.IsActive = true;
                    EntityConverter.FillEntityFromDTO(issuesDTO, issue);
                    context.Issues.Add(issue);

                    issuesDTO.IssueHistoriesDTO.AssignedTo = 1;
                    issuesDTO.IssueHistoriesDTO.Comments   = "new issue has been generated";
                    issuesDTO.IssueHistoriesDTO.ModifiedBy = 1;
                    issuesDTO.IssueHistoriesDTO.Status     = 1;
                    issuesDTO.IssueHistoriesDTO.ModifiedOn = DateTime.Now;
                    issuesDTO.IssueHistoriesDTO.IssueId    = issue.IssueId;

                    IssueHistory newissueHistory = new IssueHistory();
                    EntityConverter.FillEntityFromDTO(issuesDTO.IssueHistoriesDTO, newissueHistory);
                    context.IssueHistories.Add(newissueHistory);
                    context.SaveChanges();

                    createIssueRetval = issuesDTO;
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException(ex.Message);
            }
            return(createIssueRetval);
        }
Example #18
0
        public IDataDTO CreateVote(IVoteDTO voteDTO)
        {
            using (var context = new BufferOverflowDBEntities())
            {
                var voteEntity = context.Votes.SingleOrDefault(v => v.UserId == voteDTO.UserId && v.AnswerId == voteDTO.AnswerId);
                //context.Votes.Where(v => v.Id == voteDTO.Id).Distinct();
                if (voteEntity == null)
                {
                    Votes vote = new Votes();
                    EntityConverter.FillEntityFromDTO(voteDTO, vote);
                    context.Votes.Add(vote);
                    context.SaveChanges();
                }
                else if (voteEntity.Vote != voteDTO.Vote)
                {
                    voteEntity.Vote = voteDTO.Vote;
                    context.SaveChanges();
                }

                var countUp   = context.Votes.Where(c => c.Vote == 1 && c.AnswerId == voteDTO.AnswerId).Count();
                var countDown = context.Votes.Where(c => c.Vote == 2 && c.AnswerId == voteDTO.AnswerId).Count();

                int totalVotes = countUp - countDown;

                IDataDTO dataDTO = (IDataDTO)DTOFactory.Instance.Create(DTOType.DataDTO);
                dataDTO.TotalVote  = totalVotes;
                dataDTO.VoteDetail = voteDTO;

                return(dataDTO);
            }
        }
Example #19
0
        public IUserDTO CreateAUser(IUserDTO customer)
        {
            IUserDTO createUserRetVal = null;

            try
            {
                using (CasinoPortalEntities context = new CasinoPortalEntities())
                {
                    Player user = new Player();
                    customer.BlockedAmount  = 0;
                    customer.AccountBalance = 500;
                    EntityConverter.FillEntityFromDTO(customer, user);
                    context.Players.Add(user);

                    if (context.SaveChanges() > 0)
                    {
                        createUserRetVal          = customer;
                        createUserRetVal.PlayerId = user.PlayerId;
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException(ex.Message);
            }
            return(createUserRetVal);
        }
Example #20
0
        public IIssueHistoriesDTO UpdateIssueByAdmin(IIssueHistoriesDTO issueHistoriesDTO)
        {
            IIssueHistoriesDTO retVal = null;

            try
            {
                using (EmployeePortalEntities context = new EmployeePortalEntities())
                {
                    var updateIssueByAdmin = context.IssueHistories.First(item => issueHistoriesDTO.IssueId == item.IssueId);
                    if (updateIssueByAdmin != null)
                    {
                        issueHistoriesDTO.IssueHistoryId = updateIssueByAdmin.IssueHistoryId;
                        EntityConverter.FillEntityFromDTO(issueHistoriesDTO, updateIssueByAdmin);
                        context.SaveChanges();
                        retVal = issueHistoriesDTO;
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException(ex.Message);
            }
            return(retVal);
        }
Example #21
0
        public IUserDTO CreateUser(IUserDTO userDTO)
        {
            IUserDTO retVal = null;

            userDTO.Unique_User_Id  = userDTO.Email_Id;
            userDTO.Account_Balance = 500;
            userDTO.Blocked_Amount  = 0;

            try
            {
                using (CasioAppEntities context = new CasioAppEntities())
                {
                    CustomerList customer = new CustomerList();
                    EntityConverter.FillEntityFromDTO(userDTO, customer);
                    context.CustomerLists.Add(customer);
                    if (context.SaveChanges() > 0)
                    {
                        userDTO.Customer_Id = customer.Customer_Id;
                        retVal = userDTO;
                    }
                }
            }

            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException(ex.Message);
            }

            return(retVal);
            //throw new NotImplementedException();
        }
        /// <summary>
        /// Post action to login user
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        //[HttpPost]
        //[Route("api/user/login")]
        public User Login([FromBody] User user)
        {
            IUserDTO userDTO = (IUserDTO)DTOFactory.Instance.Create(DTOType.UserDTO);

            EntityConverter.FillDTOFromEntity(user, userDTO);

            IUserFacade userFacade            = (IUserFacade)FacadeFactory.Instance.Create(FacadeType.UserFacade);
            OperationResult <IUserDTO> result = userFacade.Login(userDTO);

            if (result.ResultType == OperationResultType.Failure)
            {
                //string failed = JsonConvert.SerializeObject(new { success = false, data = result.Message });
                //return BadRequest(failed);
                return(null);
            }

            if (result.IsValid())
            {
                EntityConverter.FillEntityFromDTO(result.Data, user);
                ////var userStore = new UserStore<ApplicationUser>(new ApplicationDbContext());
                ////var manager = new UserManager<ApplicationUser>(userStore);
                ////var user = new ApplicationUser() { UserName = model.UserName, Email = model.Email }
                //string success = JsonConvert.SerializeObject(new { success = true, data = user});
                //return Ok(success);

                return(user);
            }
            //string jsonObj = JsonConvert.SerializeObject(new { success = false, data = result.Message });
            //return BadRequest(jsonObj);
            return(null);
        }
Example #23
0
        public IAnswerDTO Edit(IAnswerDTO answerDTO)
        {
            using (var context = new BufferOverflowDBEntities())
            {
                var answerEntity = context.Answers.SingleOrDefault(a => a.Id == answerDTO.Id);

                if (answerEntity != null)
                {
                    EntityConverter.FillEntityFromDTO(answerDTO, answerEntity);
                }

                return(answerDTO);
            }
        }
Example #24
0
        public bool UpdateUser(IUserDTO userDTO)
        {
            bool retVal = false;

            using (UserStoryEntities context = new UserStoryEntities())
            {
                User user = context.Users.Where(u => u.UserId == userDTO.UserId).SingleOrDefault();
                EntityConverter.FillEntityFromDTO(userDTO, user);
                context.SaveChanges();
                retVal = true;
            }

            return(retVal);
        }
Example #25
0
        public int InsertUser(IUserDTO userDTO)
        {
            int retVal = -1;

            using (UserStoryEntities context = new UserStoryEntities())
            {
                User user = new User();
                EntityConverter.FillEntityFromDTO(userDTO, user);
                context.Users.Add(user);
                context.SaveChanges();
                retVal = user.UserId;
            }
            return(retVal);
        }
Example #26
0
        /// <summary>
        /// Method to edit question
        /// </summary>
        /// <param name="questionDTO"></param>
        /// <returns></returns>
        public IQuestionDTO Edit(IQuestionDTO questionDTO)
        {
            using (var context = new BufferOverflowDBEntities())
            {
                var questionEntity = context.Questions.SingleOrDefault(q => q.Id == questionDTO.Id);
                if (questionEntity != null)
                {
                    EntityConverter.FillEntityFromDTO(questionDTO, questionEntity);
                    context.SaveChanges();
                }
                else
                {
                    questionDTO.Id = 0;
                }

                return((questionDTO.Id != 0) ? questionDTO : null);
            }
        }
Example #27
0
        public UserDTO SignUp(UserDTO userDTO)
        {
            User        user    = new User();
            BookContext db      = new BookContext();
            string      emailID = userDTO.EmailID;

            if (db.Users.Any(e => e.EmailId == emailID))
            {
                return(null);
            }
            else
            {
                UserDTO result = new UserDTO();
                EntityConverter.FillEntityFromDTO(userDTO, user);
                db.Users.Add(user);
                db.SaveChanges();
                return(userDTO);
            }
        }
Example #28
0
        /// <summary>
        /// Method to create question
        /// </summary>
        /// <param name="questionDTO"></param>
        /// <returns></returns>
        public IQuestionDTO Create(IQuestionDTO dataDTO)
        {
            using (var context = new BufferOverflowDBEntities())
            {
                Questions questionEntity = new Questions();
                EntityConverter.FillEntityFromDTO(dataDTO, questionEntity);

                var question = context.Questions.Add(questionEntity);
                context.SaveChanges();

                IQuestionDTO questionDTO = (IQuestionDTO)DTOFactory.Instance.Create(DTOType.QuestionDTO);
                if (question != null)
                {
                    EntityConverter.FillDTOFromEntity(question, dataDTO);
                }

                return((dataDTO.Id != 0) ? dataDTO : null);;
            }
        }
        public IHttpActionResult GetQuestions()
        {
            IQuestionFacade questionFacade            = (IQuestionFacade)FacadeFactory.Instance.Create(FacadeType.QuestionFacade);
            OperationResult <List <IDataDTO> > result = questionFacade.GetQuestions();

            if (result.ResultType == OperationResultType.Failure)
            {
                string failed = JsonConvert.SerializeObject(new { success = false, data = result.Message });
                return(BadRequest(failed));
            }

            if (result.IsValid())
            {
                List <Data> dataList = new List <Data>();

                foreach (var dataDTO in result.Data)
                {
                    Data data = new Data();

                    EntityConverter.FillEntityFromDTO(dataDTO.QuestionDetail, data.QuestionDetail);

                    EntityConverter.FillEntityFromDTO(dataDTO.UserDetail, data.UserDetail);

                    List <ITagsDTO> tagsDTOList = dataDTO.TagDetail;
                    List <Tags>     tagsModel   = new List <Tags>();
                    foreach (var tagDTO in tagsDTOList)
                    {
                        Tags tag = new Tags();
                        EntityConverter.FillEntityFromDTO(tagDTO, tag);
                        tagsModel.Add(tag);
                    }

                    data.TagDetail = tagsModel;
                    dataList.Add(data);
                }
                //string success = JsonConvert.SerializeObject(new { success = true, data = dataList });
                return(Ok(result.Data[0].QuestionDetail));
            }

            string jsonObj = JsonConvert.SerializeObject(new { success = false, data = result.Message });

            return(BadRequest(jsonObj));
        }
        /// <summary>
        /// Create a new entry in issue and issue history table
        /// </summary>
        /// <param name="issueDTO"></param>
        /// <returns></returns>
        public IIssueDTO CreateIssue(IIssueDTO issueDTO)
        {
            IIssueDTO createIssueRetVal = null;

            try
            {
                using (EmployeePortal2017Entities portal = new EmployeePortal2017Entities())
                {
                    using (var transScope = new TransactionScope())
                    {
                        issueDTO.IsActive = true;
                        Issue issue = new Issue();
                        EntityConverter.FillEntityFromDTO(issueDTO, issue);
                        portal.Issues.Add(issue);
                        portal.SaveChanges();
                        issueDTO.IssueId = issue.IssueId;

                        IIssueHistoryDTO issueHistoryDTO = (IIssueHistoryDTO)DTOFactory.Instance.Create(DTOType.IssueHistoryDTO);
                        issueHistoryDTO.IssueId    = issue.IssueId;
                        issueHistoryDTO.AssignedTo = null;
                        issueHistoryDTO.Comments   = null;
                        issueHistoryDTO.ModifiedBy = issue.PostedBy;
                        issueHistoryDTO.ModifiedOn = DateTime.Now;
                        issueHistoryDTO.Status     = (int)IssueStatus.Raised;

                        IssueHistory issueHistory = new IssueHistory();
                        EntityConverter.FillEntityFromDTO(issueHistoryDTO, issueHistory);
                        portal.IssueHistories.Add(issueHistory);
                        portal.SaveChanges();
                        transScope.Complete();
                        createIssueRetVal = issueDTO;
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException(ex.Message);
            }
            return(createIssueRetVal);
        }