Exemplo n.º 1
0
        public ResponseModel<string> CreateTemplate(List<CreateTemplateQuestionInfoModel> req,string username)
        {
            var response = new ResponseModel<string>();

            var keyInfo = _db.CreateTemplateQuestionInfoes.FirstOrDefault();
            var refKey = username;
            var digitKey = 0;
            if (keyInfo != null)
            {
                digitKey = _db.CreateTemplateQuestionInfoes.Max(x => x.Id) + 1;
            }
            else
            {
                digitKey = 1;
            }
            refKey += digitKey;
            var createTemplateQuestionsInfoInsert = new CreateTemplateQuestionInfo
            {
                buttonText = "NA",
                username = username,
                title = req[0].title,
                visible = "NA",
                type = "NA",
                creationTime = DateTime.Now.ToString(CultureInfo.InvariantCulture),
                referenceId = refKey,
                total = "NA",
                completed = "NA",
                verified = "NA"
            };

            _db.CreateTemplateQuestionInfoes.Add(createTemplateQuestionsInfoInsert);

            try
            {
                _db.SaveChanges();
                CreateSubTemplateByRefKey CreateSubTemplateByRefKey = new CreateSubTemplateByRefKey();
                CreateSubTemplateByRefKey.CreateSubTemplateByRefKeyService(req, username, refKey);
                response.Status = 200;
                response.Message = "success-"+digitKey;
                response.Payload = refKey;
            }
            catch (DbEntityValidationException e)
            {
                DbContextException.LogDbContextException(e);
                response.Status = 500;
                response.Message = "Failed";
                response.Payload = "Exception Occured";
            }

            return response;
        }
Exemplo n.º 2
0
        public ResponseModel<string> CreateTemplateWithId(List<CreateTemplateQuestionInfoModel> req, string username,string id)
        {
            var response = new ResponseModel<string>();

            var refKey = username+id;

            var createTemplateQuestionsInfoInsert = new CreateTemplateQuestionInfo
            {
                buttonText = "NA",
                username = username,
                title = req[0].title,
                visible = "NA",
                type = "NA",
                creationTime = DateTime.Now.ToString(CultureInfo.InvariantCulture),
                referenceId = refKey,
                total = "NA",
                completed = "NA",
                verified = "NA"
            };

            _db.CreateTemplateQuestionInfoes.Add(createTemplateQuestionsInfoInsert);

            try
            {
                _db.SaveChanges();
                CreateSubTemplateByRefKey CreateSubTemplateByRefKey = new CreateSubTemplateByRefKey();
                CreateSubTemplateByRefKey.CreateSubTemplateByRefKeyService(req, username, refKey);
                response.Status = 200;
                response.Message = "Success";
                response.Payload = "Successfully Created";
            }
            catch (DbEntityValidationException e)
            {
                DbContextException.LogDbContextException(e);
                response.Status = 500;
                response.Message = "Failed";
                response.Payload = "Exception Occured";
            }

            return response;
        }
Exemplo n.º 3
0
        public ResponseModel<string> EditTemplateDetailById(List<CreateTemplateQuestionInfoModel> req,string username, long id)
        {
            var response = new ResponseModel<string>();
            try
            {
                var templateData = _db.CreateTemplateQuestionInfoes.SingleOrDefault(x => x.Id == id && x.username == username);
                var createTemplateeditableInstructionsListsCreateResponse = _db.CreateTemplateeditableInstructionsLists.OrderBy(x => x.Id).Where(x => x.referenceKey == templateData.referenceId && x.username == username).ToList();
                var createTemplateSingleQuestionsListsCreateResponse = _db.CreateTemplateSingleQuestionsLists.OrderBy(x => x.Id).Where(x => x.referenceKey == templateData.referenceId && x.username == username).ToList();
                var createTemplateMultipleQuestionsListsCreateResponse = _db.CreateTemplateMultipleQuestionsLists.OrderBy(x => x.Id).Where(x => x.referenceKey == templateData.referenceId && x.username == username).ToList();
                var createTemplateTextBoxQuestionsListsCreateResponse = _db.CreateTemplateTextBoxQuestionsLists.OrderBy(x => x.Id).Where(x => x.referenceKey == templateData.referenceId && x.username == username).ToList();
                var createTemplateListBoxQuestionsListsCreateResponse = _db.CreateTemplateListBoxQuestionsLists.OrderBy(x => x.Id).Where(x => x.referenceKey == templateData.referenceId && x.username == username).ToList();

                if (createTemplateeditableInstructionsListsCreateResponse != null)
                {
                    foreach (var createTemplateeditableInstructionCreateResponse in createTemplateeditableInstructionsListsCreateResponse)
                    {
                        _db.CreateTemplateeditableInstructionsLists.Remove(createTemplateeditableInstructionCreateResponse);
                    }
                }

                if (createTemplateSingleQuestionsListsCreateResponse != null)
                {
                    foreach (var createTemplateSingleQuestionCreateResponse in createTemplateSingleQuestionsListsCreateResponse)
                    {
                        _db.CreateTemplateSingleQuestionsLists.Remove(createTemplateSingleQuestionCreateResponse);
                    }
                }

                if (createTemplateMultipleQuestionsListsCreateResponse != null)
                {
                    foreach (var createTemplateMultipleQuestionCreateResponse in createTemplateMultipleQuestionsListsCreateResponse)
                    {
                        _db.CreateTemplateMultipleQuestionsLists.Remove(createTemplateMultipleQuestionCreateResponse);
                    }
                }

                if (createTemplateTextBoxQuestionsListsCreateResponse != null)
                {
                    foreach (var createTemplateTextBoxQuestionCreateResponse in createTemplateTextBoxQuestionsListsCreateResponse)
                    {
                        _db.CreateTemplateTextBoxQuestionsLists.Remove(createTemplateTextBoxQuestionCreateResponse);
                    }
                }

                if (createTemplateListBoxQuestionsListsCreateResponse != null)
                {
                    foreach (var createTemplateListBoxQuestionCreateResponse in createTemplateListBoxQuestionsListsCreateResponse)
                    {
                        _db.CreateTemplateListBoxQuestionsLists.Remove(createTemplateListBoxQuestionCreateResponse);
                    }
                }

                try
                {
                    templateData.title = req[0].title;
                    _db.SaveChanges();
                    CreateSubTemplateByRefKey CreateSubTemplateByRefKey = new CreateSubTemplateByRefKey();
                    CreateSubTemplateByRefKey.CreateSubTemplateByRefKeyService(req, username, templateData.referenceId);

                    response.Status = 200;
                    response.Message = "Success";
                    response.Payload = "Successfully Edited";
                }
                catch (DbEntityValidationException e)
                {
                    DbContextException.LogDbContextException(e);
                    response.Status = 500;
                    response.Message = "Failed";
                    response.Payload = "Exception Occured";
                }

                return response;
            }
            catch (Exception)
            {
                response.Status = 500;
                response.Message = "Exception";
                return response;
            }
        }
Exemplo n.º 4
0
        public ResponseModel<string> CreateTemplate(List<CreateTemplateQuestionInfoModel> req,string username,TemplateInfoModel TemplateInfo)
        {
            var response = new ResponseModel<string>();

            var keyInfo = _db.CreateTemplateQuestionInfoes.FirstOrDefault();
            var refKey = _db.Users.SingleOrDefault(x=>x.Username == username).guid;
            var digitKey = 0;

            Random rnd = new Random();
            int randomValue = rnd.Next(1, 10000);
            
            if (keyInfo != null)
            {
                digitKey = _db.CreateTemplateQuestionInfoes.Max(x => x.Id) + 1;                
            }
            else
            {
                digitKey = 1;                
            }
            refKey += digitKey + randomValue;

            if (TemplateInfo.type == Constants.type_Ads && TemplateInfo.subType == Constants.subType_facebookLike)
            {
                var facebookFindPageId = TemplateInfo.pageId.Split('/');
                var createTemplateFacebookLikeInsert = new CreateTemplateFacebookLike
                {                    
                    username = username,
                    title = req[0].title,                    
                    type = TemplateInfo.type,
                    subType = TemplateInfo.subType,
                    creationTime = DateTime.Now.ToString(CultureInfo.InvariantCulture),
                    referenceId = refKey,
                    totalThreads = TemplateInfo.totalThreads,
                    completed = Constants.NA,
                    verified = Constants.NA,
                    payPerUser = TemplateInfo.amountEachThread,
                    DateTime = DateTime.Now,
                    description = (req[3].textBoxQuestionsList[0].Question) == null ? Constants.NA : req[3].textBoxQuestionsList[0].Question,
                    pageId = facebookFindPageId[facebookFindPageId.Length-1],
                    pageUrl = TemplateInfo.pageUrl
                };
                _db.CreateTemplateFacebookLikes.Add(createTemplateFacebookLikeInsert);
                try
                {
                    _db.SaveChanges();
                    
                    var signalRHub = new SignalRHub();
                    string totalProjects = new ProjectDAO().totalAvailableProjects();
                    string successRate = "";
                    string totalUsers = "";
                    string projectCategories = "";
                    
                    var hubContext = GlobalHost.ConnectionManager.GetHubContext<SignalRHub>();
                    hubContext.Clients.All.updateBeforeLoginUserProjectDetails(totalProjects, successRate, totalUsers, projectCategories);


                    response.Status = 200;
                    response.Message = "success-" + digitKey;
                    response.Payload = refKey;
                }
                catch (DbEntityValidationException e)
                {
                    DbContextException.LogDbContextException(e);
                    response.Status = 500;
                    response.Message = "Failed";
                    response.Payload = "Exception Occured";
                }
            }
            else
            {
                var createTemplateQuestionsInfoInsert = new CreateTemplateQuestionInfo
                {
                    description = TemplateInfo.description != null ? TemplateInfo.description : Constants.NA,
                    username = username,
                    title = req[0].title,
                    visible = Constants.NA,
                    type = TemplateInfo.type,
                    subType = TemplateInfo.subType,
                    creationTime = DateTime.Now.ToString(CultureInfo.InvariantCulture),
                    referenceId = refKey,
                    totalThreads = TemplateInfo.totalThreads,
                    completed = Constants.NA,
                    verified = Constants.NA,
                    payPerUser = TemplateInfo.amountEachThread
                };

                _db.CreateTemplateQuestionInfoes.Add(createTemplateQuestionsInfoInsert);

                try
                {
                    _db.SaveChanges();
                    
                    CreateSubTemplateByRefKey CreateSubTemplateByRefKey = new CreateSubTemplateByRefKey();
                    CreateSubTemplateByRefKey.CreateSubTemplateByRefKeyService(req, username, refKey);

                    var signalRHub = new SignalRHub();
                    string totalProjects = new ProjectDAO().totalAvailableProjects();
                    string successRate = "";
                    string totalUsers = "";
                    string projectCategories = "";
                    var hubContext = GlobalHost.ConnectionManager.GetHubContext<SignalRHub>();
                    hubContext.Clients.All.updateBeforeLoginUserProjectDetails(totalProjects, successRate, totalUsers, projectCategories);

                    new SendNewTaskService().SendUserTaskNotificationToAllAsync(createTemplateQuestionsInfoInsert.title, "Total " + createTemplateQuestionsInfoInsert.totalThreads+" available",DateTime.Now);
                   
                    response.Status = 200;
                    response.Message = "success-" + digitKey;
                    response.Payload = refKey;
                }
                catch (DbEntityValidationException e)
                {
                    DbContextException.LogDbContextException(e);
                    response.Status = 500;
                    response.Message = "Failed";
                    response.Payload = "Exception Occured";
                }
            }
            
            return response;
        }