コード例 #1
0
        public IHttpActionResult Index(FilterNote filter)
        {
            var    routeDataValues = ControllerContext.RouteData.Values;
            int    parentId;
            string typeValue   = routeDataValues["Type"].ToString();
            bool   hasParentId = int.TryParse(routeDataValues["ParentId"].ToString(), out parentId);

            if (hasParentId)
            {
                filter.ParentId = parentId;
                switch (typeValue)
                {
                case "tasks":
                    filter.ParentTypeId = (int)NoteType.Task;
                    break;

                case "leads":
                case "accounts":
                    filter.ParentTypeId = (int)NoteType.Lead;
                    break;
                }

                var repository = new RepositoryNote();
                var response   = repository.GetAllNotes(filter, CurrentBusinessId.Value);
                return(Ok <DataResponse <EntityList <EntityNote> > >(response));
            }
            else
            {
                return(Ok());
            }
        }
コード例 #2
0
        public IHttpActionResult InsertNotedata(VMNoteModel entity)
        {
            var repository = new RepositoryNote();
            var response   = new DataResponse <EntityNote>();

            if (ModelState.IsValid)
            {
                string typeValue = ControllerContext.RouteData.Values["Type"].ToString();
                entity.ParentId = int.Parse(ControllerContext.RouteData.Values["ParentId"].ToString());

                switch (typeValue)
                {
                case "tasks":
                    entity.ParentTypeId = (int)NoteType.Task;
                    break;

                case "leads":
                case "accounts":
                    entity.ParentTypeId = (int)NoteType.Lead;
                    break;
                }

                var model = new EntityNote
                {
                    Id            = entity.Id,
                    ParentId      = entity.ParentId,
                    ParentTypeId  = entity.ParentTypeId,
                    CreatedBy     = CurrentUser.Id,
                    UpdatedBy     = CurrentUser.Id,
                    Description   = entity.Description,
                    CreatedOn     = DateTime.UtcNow,
                    BusinessId    = CurrentBusinessId,
                    CreatedByName = string.Format("{0} {1}", CurrentUser.FirstName, CurrentUser.LastName)
                };

                response = repository.SaveNote(model);
            }
            else
            {
                var errorList = ModelState.Where(a => a.Value.Errors.Any()).Select(s => new
                {
                    Key     = s.Key.Split('.').Last(),
                    Message = s.Value.Errors[0].ErrorMessage
                });
                return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = errorList }));
            }
            var dataResponse = repository.GetNoteById(response.Model.ParentId, response.Model.ParentTypeId);

            // response.Message = response.Model.CreatedOn.ToString("yyyy-MM-dd HH:mm:ss:fff");
            //response.Model.CreatedOn = DateTime.Parse(response.Model.CreatedOn.ToString("yyyy-MM-dd HH:mm:ss:fff"));
            return(Ok <DataResponse>(dataResponse));
        }
コード例 #3
0
        public IHttpActionResult DeleteNote(int id)
        {
            var DeleteNote = new RepositoryNote().DeleteNote(id);

            if (DeleteNote)
            {
                return(Ok <dynamic>(new { IsSuccess = 1, Status = 200, Message = "Note deleted!" }));
            }
            else
            {
                return(Ok <dynamic>(new { IsSuccess = 0, Message = "Note Notfound!" }));
            }
        }
コード例 #4
0
        //"Server=.;Database=PentruLaborator;Trusted_Connection=True;" providerName="System.Data.SqlClient"
        static void Main(string[] args)
        {
            ValidatorStudent   val   = new ValidatorStudent();
            RepositoryStudenti repo  = new RepositoryStudenti(val);
            RepositoryTeme     repoT = new RepositoryTeme(new ValidatorTema());
            RepositoryNote     repoN = new RepositoryNote(new ValidatorNota());
            StudentServices    ctrlS = new StudentServices(repo);
            TemeServices       ctrlT = new TemeServices(repoT);
            NoteServices       ctrlN = new NoteServices(repoN, repo, repoT);
            Consola            cons  = new Consola(ctrlS, ctrlT, ctrlN);

            cons.runMenu();
        }
コード例 #5
0
 public NoteServices(RepositoryNote repo, RepositoryStudenti repoS, RepositoryTeme repoT)
 {
     this.repo  = repo;
     this.repoS = repoS;
     this.repoT = repoT;
 }
コード例 #6
0
        public IHttpActionResult InsertNotedata(VMNoteModel entity)
        {
            var repository = new RepositoryNote();
            var response   = new DataResponse();

            if (ModelState.IsValid)
            {
                string typeValue = ControllerContext.RouteData.Values["Type"].ToString();
                entity.ParentId = int.Parse(ControllerContext.RouteData.Values["ParentId"].ToString());

                switch (typeValue)
                {
                case "tasks":
                    entity.ParentTypeId = (int)NoteType.Task;
                    break;

                case "leads":
                    entity.ParentTypeId = (int)NoteType.Lead;
                    break;
                }

                var model = new EntityNote
                {
                    Id           = entity.Id,
                    ParentId     = entity.ParentId,
                    ParentTypeId = entity.ParentTypeId,
                    CreatedBy    = CurrentUser.Id,
                    UpdatedBy    = CurrentUser.Id,
                    Description  = entity.Description,
                };

                response = repository.SaveNote(model);
                if (entity.ParentTypeId == (int)NoteType.Task && response.Message == "OK")
                {
                    #region Send email to users in assigned to and watchers list
                    var CreatedByName = string.Format("{0} {1}", CurrentUser.FirstName, CurrentUser.LastName);
                    var TaskModel     = new RepositoryTask().GetTaskById(model.ParentId, CurrentUserId, CurrentBusinessId);
                    try
                    {
                        var    rootPath  = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
                        var    ReturnUrl = ConfigurationManager.AppSettings["BaseUrl"] + CurrentUser.BusinessName.Replace(" ", "-") + "#/tasks/" + TaskModel.Model.ReferenceNumber;
                        var    Subject   = "Task " + TaskModel.Model.ReferenceNumber + " - " + TaskModel.Model.Subject + "";
                        var    mail      = new GMEmail();
                        string toEmails  = null;
                        if (CurrentUserId != TaskModel.Model.RequestedUser.UserId)
                        {
                            try
                            {
                                var emailBody = TemplateManager.NewNote(rootPath, TaskModel.Model.RequestedUser.Name, CreatedByName, TaskModel.Model.Subject, ReturnUrl, entity.Description, CurrentBusinessId.Value, CurrentUser.RelativeUrl);
                                mail.SendDynamicHTMLEmail(TaskModel.Model.RequestedUser.Email, Subject, emailBody, CurrentUser.OtherEmails);
                            }
                            catch (Exception ex)
                            {
                                ex.Log();
                            }
                        }
                        var UserList = TaskModel.Model.AssignedUsersList.Concat(TaskModel.Model.WatchersList);
                        foreach (var item in UserList)
                        {
                            if (item.UserId == CurrentUserId)
                            {
                                continue;
                            }

                            var emailBody = TemplateManager.NewNote(rootPath, item.Name, CreatedByName, TaskModel.Model.Subject, ReturnUrl, entity.Description, CurrentBusinessId.Value, CurrentUser.RelativeUrl);
                            try
                            {
                                toEmails = new RepositoryUserProfile().NotificationEnabledEmails(item.Email, "TSKNOTENFN");
                                if (!string.IsNullOrEmpty(toEmails))
                                {
                                    mail.SendDynamicHTMLEmail(item.Email, Subject, emailBody, CurrentUser.OtherEmails);
                                }
                            }
                            catch (Exception ex)
                            {
                                ex.Log();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ex.Log();
                    }

                    #endregion
                }
            }
            else
            {
                var errorList = ModelState.Where(a => a.Value.Errors.Any()).Select(s => new
                {
                    Key     = s.Key.Split('.').Last(),
                    Message = s.Value.Errors[0].ErrorMessage
                });
                return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = errorList }));
            }
            return(Ok <DataResponse>(response));
        }