Ejemplo n.º 1
0
        public static Data.Notification Create(string title, string message, bool important, DataType data_type, long data_id)
        {
            var dt = "";
            switch(data_type)
            {
            case DataType.Drug:
                dt = "drug";
                break;
            case DataType.DrugCompany:
                dt = "drug-company";
                break;
            default:
                throw new ArgumentOutOfRangeException("Unrecognized value for data_type");
            }

            var ret = new Data.Notification() {
                DataID = data_id,
                DataType = dt,
                Important = important ? "yes" : "no",
                Link = BuildNotificationUrl(data_type, data_id),
                Message = message,
                Sent = DateTime.Now,
                Title = title,
            };

            ret.Save();

            return ret;
        }
 public void Add(Data.Notification entity, int LoggedInUserId, int LoggedInOrganizationId)
 {
     entity.AddedBy        = LoggedInUserId;
     entity.Added_Date     = DateTime.Now;
     entity.OrganizationId = LoggedInOrganizationId;
     base.Insert(entity);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Adds the notification.
 /// </summary>
 /// <param name="notification">The notification.</param>
 /// <param name="shouldSave">if set to <c>true</c> [should save].</param>
 public void AddNotification(Data.Notification notification, bool shouldSave = true)
 {
     DataContext.Notifications.AddObject(notification);
     if (shouldSave)
     {
         this.SaveChanges();
     }
 }
Ejemplo n.º 4
0
        public static Data.Notification Create(string title, string message, bool important, string link)
        {
            var ret = new Data.Notification()
            {
                DataType = "link",
                Important = important ? "yes" : "no",
                Link = link,
                LinkType = "link",
                Message = message,
                Sent = DateTime.Now,
                Title = title,
            };

            ret.Save();

            return ret;
        }
Ejemplo n.º 5
0
 public void CheckBirthdayRegistration()
 {
     Data.Notification objData = new Data.Notification(string.Empty);
     objData.CheckBirthdayRegistration();
 }
Ejemplo n.º 6
0
 public int SendNotification()
 {
     Data.Notification objData = new Data.Notification(string.Empty);
     return(objData.SendNotification());
 }
Ejemplo n.º 7
0
 public int CreateNotification()
 {
     Data.Notification objData = new Data.Notification(_4screen.CSB.Common.WebRootPath.Instance.ToString());
     return(objData.GetPending());
 }
Ejemplo n.º 8
0
 public void AllocateNotification()
 {
     Data.Notification objData = new Data.Notification(string.Empty);
     objData.AllocateNotification();
 }
 public void Update(Data.Notification entity, int LoggedInUserId, int LoggedInOrganizationId)
 {
     base.Update(entity);
     _unitOfWork.Save();
 }
Ejemplo n.º 10
0
        public HttpResponseMessage PostFormData()
        {
            var    UploadPath = "";
            string path       = "";

            Data.Notification nobj = new Data.Notification();
            foreach (string file in HttpContext.Current.Request.Files)
            {
                var FileDataContent = System.Web.HttpContext.Current.Request.Files[file];
                var myObject        = System.Web.HttpContext.Current.Request;
                nobj.MessageType = myObject.Form["MessageType"];
                nobj.MessageText = myObject.Form["MessageText"];
                Console.WriteLine("My class Id: " + myObject.Form["ClassId"]);
                nobj.ClassId   = Convert.ToInt32(myObject.Form["ClassId"]);
                nobj.SectionId = Convert.ToInt32(myObject.Form["SectionId"]);
                nobj.StudentId = myObject.Form["StudentId"];
                nobj.Subject   = myObject.Form["Subject"];
                nobj.SchoolId  = Convert.ToInt32(myObject.Form["SchoolId"]);
                if (FileDataContent != null && FileDataContent.ContentLength > 0)
                {
                    try
                    {
                        var stream   = FileDataContent.InputStream;
                        var guidKey  = Guid.NewGuid();
                        var fileName = Path.GetFileName(FileDataContent.FileName);
                        fileName = guidKey + "_" + fileName;
                        //UploadPath = AppDomain.CurrentDomain.BaseDirectory + "\\Attachments\\";
                        string pathToFiles = HttpContext.Current.Server.MapPath("~/SchoolWepAPI");
                        UploadPath = pathToFiles + "\\Attachments\\";
                        Directory.CreateDirectory(UploadPath);
                        path = Path.Combine(UploadPath, fileName);

                        if (System.IO.File.Exists(path))
                        {
                            System.IO.File.Delete(path);
                        }
                        using (var fileStream = System.IO.File.Create(path))
                        {
                            stream.CopyTo(fileStream);
                            nobj.FilePath = "Attachments\\" + fileName;
                            fileStream.Dispose();
                            nobj.CreatedDate = DateTime.Now;
                            try
                            {
                                this._dbContext.Notifications.Add(nobj);
                                this._dbContext.SaveChanges();
                            }
                            catch (Exception Ex)
                            {
                                if (System.IO.File.Exists(path))
                                {
                                    System.IO.File.Delete(path);
                                }
                                return(new HttpResponseMessage()
                                {
                                    StatusCode = System.Net.HttpStatusCode.InternalServerError,
                                    Content = new StringContent("File deleted." + path),
                                    ReasonPhrase = UploadPath
                                });
                            }
                        }
                    }
                    catch (IOException ex)
                    {
                        //return nobj;
                        return(new HttpResponseMessage()
                        {
                            StatusCode = System.Net.HttpStatusCode.InternalServerError,
                            Content = new StringContent("Files are not uploaded."),
                            ReasonPhrase = path
                        });
                    }
                }
            }
            //return nobj;
            return(new HttpResponseMessage()
            {
                StatusCode = System.Net.HttpStatusCode.OK,
                Content = new StringContent("Notification Added."),
                ReasonPhrase = UploadPath
            });
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Accepts the invitation.
        /// </summary>
        /// <param name="invitationId">The invitation identifier.</param>
        /// <param name="userId">The user identifier.</param>
        public void AcceptInvitation(int invitationId, int userId)
        {
            Invitation invitation          = DataContext.Invitations.Where(inv => inv.InvitationId == invitationId).FirstOrDefault();
            var        invitationUserRoles = DataContext.InvitationUserRoles.Where(iur => iur.InvitationId == invitationId && iur.IsActive);

            Code invitationTypeCode = Utils.GetCodeByCodeId(invitation.InvitationTypeCodeId);
            User user = GetUser(userId);

            #region Create project/company user

            if (invitationTypeCode.Value == "PROJECTTEAM")
            {
                int projectId = invitation.RelatedId;
                InvitationUserRole projectInvitationUserRole = invitationUserRoles.FirstOrDefault();

                if (projectInvitationUserRole != null)
                {
                    //Create a new project user and save
                    ProjectUser projUser = new ProjectUser();
                    projUser.ProjectId             = projectId;
                    projUser.UserId                = invitation.ToUserId.Value;
                    projUser.ProjectUserTypeCodeId = projectInvitationUserRole.UserTypeCodeId;
                    projUser.Role                = invitation.ProjectRole;
                    projUser.IsActive            = true;
                    projUser.CreatedByUserId     = projUser.LastUpdatedByUserId = userId;
                    projUser.CreatedDate         = projUser.LastUpdatedDate = Utils.Now;
                    projUser.CanSeeBudgetSummary = invitation.CanSeeProjectBudgetSummary;
                    DataContext.ProjectUsers.AddObject(projUser);

                    #region Notifications

                    Data.Notification nf = new Data.Notification();
                    nf.ModuleTypeCodeId    = Utils.GetCodeIdByCodeValue("ModuleType", "PROJTEAM");
                    nf.OperationTypeCodeId = Utils.GetCodeIdByCodeValue("OperationType", "ADD");
                    nf.RelatedId           = invitation.RelatedId;
                    nf.ProjectId           = invitation.RelatedId;
                    nf.Message             = string.Format("{0} accepted the Project invitation.", (user.FirstName + " " + user.LastName).Trim());
                    nf.CreatedByUserId     = nf.LastUpdatedByUserId = userId;
                    nf.CreatedDate         = nf.LastUpdatedDate = Utils.Now;
                    DataContext.Notifications.AddObject(nf);

                    #endregion Notifications

                    #region Project Notification Setting

                    //Get the current latest notification Id for the project.
                    int maxNotificationId = DataContext.Notifications.Where(pnf => pnf.ProjectId == projectId).Max(pnf => pnf.NotificationId);

                    //Create a project notification setting for this user (if it doesn't exist already)
                    UserNotificationSetting unf = DataContext.UserNotificationSettings.Where(s => s.RelatedTable == "Project" && s.RelatedId == projectId && s.UserID == userId).FirstOrDefault();
                    if (unf == null)
                    {
                        unf = new UserNotificationSetting();
                        unf.RelatedTable       = "Project";
                        unf.RelatedId          = projectId;
                        unf.UserID             = userId;
                        unf.LastNotificationId = maxNotificationId;
                        unf.CreatedBy          = unf.LastUpdatedBy = userId;
                        unf.CreatedDate        = unf.LastUpdatedDate = Utils.Now;
                        DataContext.UserNotificationSettings.AddObject(unf);
                    }

                    #endregion Project Notification Setting

                    //Update Project Daily Usage Summary
                    //ProjectUsageHandler.UpdateProjectUsage(DataContext.Projects.Where(p => p.ProjectId == projectId).FirstOrDefault(), userId, projUser.UserId, false, Utils.Today, DataContext);
                }
            }
            else if (invitationTypeCode.Value == "COMPANYADMIN" || invitationTypeCode.Value == "INVENTORYTEAM")
            {
                CompanyBL   companyBL   = new CompanyBL(DataContext);
                CompanyUser companyUser = companyBL.GetCompanyUserByUserIdAndCompanyId(userId, invitation.RelatedId);

                bool addNewCompanyUser = false;
                if (companyUser == null)
                {
                    companyUser             = new CompanyUser();
                    companyUser.CompanyId   = invitation.RelatedId;
                    companyUser.UserId      = invitation.ToUserId.Value;
                    companyUser.CreatedDate = companyUser.LastUpdatedDate = Utils.Now;
                    addNewCompanyUser       = true;
                }

                //companyUser.CompanyUserTypeCodeId = invitation.UserTypeCodeId;
                companyUser.IsActive        = true;
                companyUser.CreatedByUserId = companyUser.LastUpdatedByUserId = userId;

                foreach (InvitationUserRole invitationUserRole in invitationUserRoles)
                {
                    companyUser.CompanyUserRoles.Add(
                        new CompanyUserRole
                    {
                        IsActive = true,
                        CompanyUserTypeCodeId = invitationUserRole.UserTypeCodeId,
                        CreatedByUserId       = userId,
                        CreatedDate           = Utils.Now,
                        LastUpdatedByUserId   = userId,
                        LastUpdatedDate       = Utils.Now,
                        LocationId            = invitationUserRole.LocationId
                    }
                        );
                }

                if (addNewCompanyUser)
                {
                    DataContext.CompanyUsers.AddObject(companyUser);
                }
            }

            #endregion Create project/company user

            //Mark the invitation as Accepted
            invitation.InvitationStatusCodeId = Utils.GetCodeIdByCodeValue("InvitationStatus", "ACCEPTED");
            invitation.LastUpdatedByUserId    = userId;
            invitation.LastUpdatedDate        = Utils.Now;

            DataContext.SaveChanges();

            #region Check for pending invitations to the same project/company and discard them

            int pendingInvitationCodeId = Utils.GetCodeIdByCodeValue("InvitationStatus", "PENDING");
            var simillarInvitations     = DataContext.Invitations.Where(inv => inv.ToUserId == userId && inv.InvitationStatusCodeId == pendingInvitationCodeId && inv.RelatedId == invitation.RelatedId && inv.InvitationTypeCodeId == invitation.InvitationTypeCodeId);

            foreach (Invitation inv in simillarInvitations)
            {
                DataContext.DeleteInvitation(inv.InvitationId);
            }

            #endregion Check for pending invitations to the same project/company and discard them
        }