Пример #1
0
        public IActionResult Edit(int id)
        {
            var list = new List <SelectListItem>();

            for (var i = 1; i <= _stagesServices.Count(a => a.Active == true); i++)
            {
                list.Add(new SelectListItem {
                    Text = i.ToString(), Value = i.ToString()
                });
            }
            ViewBag.list       = list;
            ViewData["stages"] = _stagesServices.GetAll(a => a.Active == true);
            return(View(_pipelineServices.Find(id)));
        }
Пример #2
0
                                                       


 public IActionResult Setup() 

                                                       {
                                                           if (_pipelineService.Count() <= 0)
                                                           {
                                                               var businessEntity = _currentUser.GetCurrentBusinessEntityId();
                                                               var userSetting    = _currentUser.Id();

                                                               if (!string.IsNullOrEmpty(businessEntity))
                                                               {
                                                                   var pipeline = new Pipeline("Pipeline")
                                                                   {
                                                                       BusinessEntityId = businessEntity, UserSettingId = userSetting
                                                                   };
                                                                   List <Stage>     stage     = new List <Stage>();
                                                                   List <TaskGroup> taskGroup = new List <TaskGroup>();


                                                                   stage.Add(new Stage()
                    {
                        BusinessEntityId = businessEntity, Pipeline = pipeline, OrderStage = 1, Name = "Lead Id"
                    });
                                                                   stage.Add(new Stage()
                    {
                        BusinessEntityId = businessEntity, Pipeline = pipeline, OrderStage = 2, Name = "Contato Feito"
                    });
                                                                   stage.Add(new Stage()
                    {
                        BusinessEntityId = businessEntity, Pipeline = pipeline, OrderStage = 3, Name = "Lead Qualificado"
                    });
                                                                   stage.Add(new Stage()
                    {
                        BusinessEntityId = businessEntity, Pipeline = pipeline, OrderStage = 4, Name = "Demo Agendada"
                    });
                                                                   stage.Add(new Stage()
                    {
                        BusinessEntityId = businessEntity, Pipeline = pipeline, OrderStage = 5, Name = "Negociações Feitas"
                    });
                                                                   stage.Add(new Stage()
                    {
                        BusinessEntityId = businessEntity, Pipeline = pipeline, OrderStage = 6, Name = "Fechamento"
                    });

                                                                   taskGroup.Add(new TaskGroup()
                    {
                        BusinessEntityId = businessEntity, Name = "Ligação"
                    });
                                                                   taskGroup.Add(new TaskGroup()
                    {
                        BusinessEntityId = businessEntity, Name = "Reunião"
                    });
                                                                   taskGroup.Add(new TaskGroup()
                    {
                        BusinessEntityId = businessEntity, Name = "Email"
                    });
                                                                   taskGroup.Add(new TaskGroup()
                    {
                        BusinessEntityId = businessEntity, Name = "Almoço"
                    });
                                                                   taskGroup.Add(new TaskGroup()
                    {
                        BusinessEntityId = businessEntity, Name = "Tarefa"
                    });
                                                                   taskGroup.Add(new TaskGroup()
                    {
                        BusinessEntityId = businessEntity, Name = "Apresentação"
                    });

                                                                   _pipelineService.Add(pipeline);
                                                                   stage.ForEach(a => _stageService.Add(a));
                                                                   taskGroup.ForEach(a => _taskGroupService.Add(a));
                                                               }
                                                           }
                                                           
            return(View()); 

                                                       }
Пример #3
0
        public JsonResult Move(int id, int PipelineId, int StageId, bool Moveforward)
        {
            if (HasTaskRequired(id))
            {
                return(Json(new { nok = "Existem tarefas a serem finalizadas antes de movimentar este negócio" }));
            }



            var data = _dealServices.Find(id);

            data.PipelineId = PipelineId;
            data.StageId    = StageId;

            var stages       = _stageServices.GetAll(p => p.PipelineId == PipelineId && p.Active == true);
            var currentOrder = _stageServices.Find(StageId).OrderStage;

            if (Moveforward)
            {
                try
                {
                    var nextOrder = stages.Where(a => a.OrderStage > currentOrder).Min(p => p.OrderStage);
                    var nextStage = stages.Where(a => a.OrderStage == nextOrder).FirstOrDefault();
                    data.StageId = nextStage.StageId;
                }
                catch (Exception)
                {
                    ;
                }
            }
            else
            {
                try
                {
                    var previousOrder = stages.Where(a => a.OrderStage < currentOrder).Max(p => p.OrderStage);
                    var previousStage = stages.Where(a => a.OrderStage == previousOrder).FirstOrDefault();
                    data.StageId = previousStage.StageId;
                }
                catch (Exception)
                {
                    ;
                }
            }


            try
            {
                _dealServices.Update(data);
                AddNewStage(data.DealId, data.StageId);
            }
            catch (Exception e)
            {
                return(Json(new { nok = e.InnerException.Message }));
            }

            var _data = new UpdateDealViewModel()
            {
                Deal     = data,
                Qty      = _dealServices.Count(a => a.PipelineId == data.PipelineId && a.StageId == data.StageId),
                StageId  = data.StageId,
                SubTotal = _dealServices.Query(a => a.PipelineId == data.PipelineId && a.StageId == data.StageId).Select(p => p.UnitPrice).DefaultIfEmpty(0).Sum().Value.ToString("c")
            };

            return(Json(_data));
        }
Пример #4
0
        public async Task <IActionResult> Register(RegisterViewModel model, byte[] AvatarImage = null, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var roleAdmin = new IdentityRole("Admin");
                var roleuser  = new IdentityRole("User");

                // User claim for write task data
                user.Claims.Add(new IdentityUserClaim <string>
                {
                    ClaimType  = "Task",
                    ClaimValue = "Write"
                });


                var roleExists = _rolesManager.RoleExistsAsync(roleAdmin.Name).Result;


                if (!roleExists)
                {
                    var resulRoles = await _rolesManager.CreateAsync(roleAdmin);

                    if (resulRoles.Succeeded)
                    {
                        roleExists = _rolesManager.RoleExistsAsync(roleuser.Name).Result;
                        resulRoles = await _rolesManager.CreateAsync(roleuser);
                    }
                }

                var roleid = await _rolesManager.FindByNameAsync(roleAdmin.Name);

                user.Roles.Add(new IdentityUserRole <string>
                {
                    RoleId = roleid.Id,
                    UserId = user.Id
                });

                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var businessEntity = new BusinessEntity(model.Name, model.Email, true);
                    var userSetting    = new UserSetting("", model.Name, "", "", businessEntity, user)
                    {
                        AvatarImage = AvatarImage, UserSettingId = user.Id
                    };
                    var userBusinessEntity = new UserBusinessEntity(businessEntity, userSetting);
                    _userBusinessEntityService.Add(userBusinessEntity);
                    //_userSettingService.Add(userSetting);

                    if (_pipelineService.Count() <= 0)
                    {
                        var pipeline = new Pipeline("Pipeline")
                        {
                            BusinessEntity = businessEntity, UserSettingId = user.Id
                        };
                        List <Stage>     stage     = new List <Stage>();
                        List <TaskGroup> taskGroup = new List <TaskGroup>();


                        stage.Add(new Stage()
                        {
                            BusinessEntity = businessEntity, Pipeline = pipeline, OrderStage = 1, Name = "Cliente potencial"
                        });
                        stage.Add(new Stage()
                        {
                            BusinessEntity = businessEntity, Pipeline = pipeline, OrderStage = 2, Name = "Contatado"
                        });
                        stage.Add(new Stage()
                        {
                            BusinessEntity = businessEntity, Pipeline = pipeline, OrderStage = 3, Name = "Demo Agendada"
                        });
                        stage.Add(new Stage()
                        {
                            BusinessEntity = businessEntity, Pipeline = pipeline, OrderStage = 4, Name = "Proposta Feita"
                        });
                        stage.Add(new Stage()
                        {
                            BusinessEntity = businessEntity, Pipeline = pipeline, OrderStage = 5, Name = "Negociações começadas"
                        });

                        taskGroup.Add(new TaskGroup()
                        {
                            BusinessEntity = businessEntity, Name = "Ligação"
                        });
                        taskGroup.Add(new TaskGroup()
                        {
                            BusinessEntity = businessEntity, Name = "Reunião"
                        });
                        taskGroup.Add(new TaskGroup()
                        {
                            BusinessEntity = businessEntity, Name = "Email"
                        });
                        taskGroup.Add(new TaskGroup()
                        {
                            BusinessEntity = businessEntity, Name = "Almoço"
                        });
                        taskGroup.Add(new TaskGroup()
                        {
                            BusinessEntity = businessEntity, Name = "Tarefa"
                        });
                        taskGroup.Add(new TaskGroup()
                        {
                            BusinessEntity = businessEntity, Name = "Apresentação"
                        });

                        _pipelineService.Add(pipeline);
                        stage.ForEach(a => _stageService.Add(a));
                        taskGroup.ForEach(a => _taskGroupService.Add(a));
                    }

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=532713
                    // Send an email with this link
                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Action(nameof(ConfirmEmail), "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
                    await _emailSender.SendEmailAsync(model.Email, "Confirm your account",
                                                      $"<p>Por favor, confirme seu email clicando neste link : <a href='{callbackUrl}'>link</a>" + "</p>");

                    //await _signInManager.SignInAsync(user, isPersistent: false);
                    _logger.LogInformation(3, "User created a new account with password.");
                    return(RedirectToLocal(returnUrl));
                    //return RedirectToAction("Setup","Home", new { user = user });
                }

                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }