Beispiel #1
0
 public int Add(User user)
 {
     user.PasswordSalt        = PasswordService.GenerateSalt();
     user.PasswordHash        = PasswordService.EncodePassword(user.Password, user.PasswordSalt);
     user.DateCreatedUtc      = DateTimeOffset.UtcNow;
     user.LastActivityDateUtc = DateTimeOffset.UtcNow;
     user.LastUpdatedUtc      = DateTimeOffset.UtcNow;
     user.PasswordLastChanged = DateTime.UtcNow;
     using (PunchClockDbContext context = new PunchClockDbContext())
     {
         if (context.Users.Any(x => x.UserName.Equals(user.UserName, StringComparison.OrdinalIgnoreCase)))
         {
             return((int)RegistrationStatus.UserNameNotAvailable);
         }
         var company =
             context.Companies.FirstOrDefault(
                 x => x.RegisterCode.Equals(user.RegistrationCode, StringComparison.OrdinalIgnoreCase));
         if (company == null)
         {
             return((int)RegistrationStatus.InvalidRegistrationCode);
         }
         user.CompanyId = company.Id;
         if (user.UserTypeId == (int)UserType.Manager)
         {
             user.IsActive = false;
         }
         context.Users.Add(user);
         context.SaveChanges();
     }
     return(user.Uid);
 }
Beispiel #2
0
 public Ticket Update(Ticket ticket, ref List <ChangeLog> changeLogs)
 {
     using (var context = new PunchClockDbContext())
     {
         var entity = context.Tickets.FirstOrDefault(x => x.Id == ticket.Id);
         if (entity == null)
         {
             return(ticket);
         }
         entity.Title           = ticket.Title;
         entity.ProjectId       = ticket.ProjectId;
         entity.PriorityId      = ticket.PriorityId;
         entity.Description     = ticket.Description;
         entity.StatusId        = ticket.StatusId;
         entity.TypeId          = ticket.TypeId;
         entity.RequestorId     = ticket.RequestorId;
         entity.AssignedToId    = ticket.AssignedToId;
         entity.NotifyTo        = ticket.NotifyTo;
         entity.CategoryId      = ticket.CategoryId;
         entity.EstimatedEffort = ticket.EstimatedEffort;
         entity.CompletedWork   = ticket.CompletedWork;
         if (ticket.DueDateUtc.HasValue)
         {
             entity.DueDateUtc = ticket.DueDateUtc.Value.ToUniversalTime();
         }
         if (ticket.Comments != null && ticket.Comments.Any())
         {
             context.TicketComments.AddOrUpdate(ticket.Comments.ToArray());
         }
         changeLogs = context.GetEntityChanges();
         context.SaveChanges();
     }
     return(ticket);
 }
Beispiel #3
0
 public void Add(SiteMap siteMap)
 {
     using (var context = new PunchClockDbContext())
     {
         context.SiteMaps.Add(siteMap);
         context.SaveChanges();
     }
 }
Beispiel #4
0
 public void Add(Punch punch)
 {
     using (PunchClockDbContext context = new PunchClockDbContext())
     {
         context.Punches.Add(punch);
         context.SaveChanges();
     }
 }
Beispiel #5
0
 public TicketType Add(TicketType type)
 {
     using (var context = new PunchClockDbContext())
     {
         context.TicketTypes.Add(type);
         context.SaveChanges();
     }
     return(type);
 }
Beispiel #6
0
 public TicketProject Add(TicketProject project)
 {
     using (var context = new PunchClockDbContext())
     {
         context.TicketProjects.Add(project);
         context.SaveChanges();
     }
     return(project);
 }
Beispiel #7
0
 public int Add(AppSetting appSetting)
 {
     using (PunchClockDbContext context = new PunchClockDbContext())
     {
         context.AppSettings.Add(appSetting);
         context.SaveChanges();
         return(appSetting.Id);
     }
 }
Beispiel #8
0
 public TicketStatus Add(TicketStatus status)
 {
     using (var context = new PunchClockDbContext())
     {
         context.TicketStatuses.Add(status);
         context.SaveChanges();
     }
     return(status);
 }
Beispiel #9
0
 public TicketPriority Add(TicketPriority priority)
 {
     using (var context = new PunchClockDbContext())
     {
         context.TicketPriorities.Add(priority);
         context.SaveChanges();
     }
     return(priority);
 }
Beispiel #10
0
 public ArticleCategory Add(ArticleCategory category)
 {
     using (var context = new PunchClockDbContext())
     {
         context.ArticleCategrories.Add(category);
         context.ArticleCategoryResources.AddRange(category.Resources);
         context.SaveChanges();
     }
     return(category);
 }
 public TicketAttachment Add(TicketAttachment attachment)
 {
     using (var context = new PunchClockDbContext())
     {
         attachment.CreatedDateUtc = DateTime.UtcNow;
         context.TicketAttachments.Add(attachment);
         context.SaveChanges();
     }
     return(attachment);
 }
Beispiel #12
0
 public ArticleComment Add(ArticleComment comment)
 {
     using (var context = new PunchClockDbContext())
     {
         comment.IsDeleted = false;
         context.ArticleComments.Add(comment);
         context.SaveChanges();
     }
     return(comment);
 }
Beispiel #13
0
 public TicketCategory Add(TicketCategory category)
 {
     using (var context = new PunchClockDbContext())
     {
         context.TicketCategories.Add(category);
         context.SaveChanges();
         category = context.TicketCategories.Include(x => x.TicketProject).FirstOrDefault(x => x.Id == category.Id);;
     }
     return(category);
 }
Beispiel #14
0
 public ArticleTag Add(ArticleTag articleTag)
 {
     using (var context = new PunchClockDbContext())
     {
         articleTag.IsDeleted = false;
         context.ArticleTags.Add(articleTag);
         context.ArticleTagResources.AddRange(articleTag.Resources);
         context.SaveChanges();
     }
     return(articleTag);
 }
Beispiel #15
0
 public string Invite(EmployeeInvite invite)
 {
     using (PunchClockDbContext context = new PunchClockDbContext())
     {
         invite.GlobalId = Guid.NewGuid().ToString("D");
         invite.UserType = context.UserTypes.FirstOrDefault(x => x.Id == invite.UserTypeId);
         context.EmployeeInvites.AddOrUpdate(invite);
         context.SaveChanges();
         return(invite.GlobalId);
     }
 }
Beispiel #16
0
 public int AddAddress(Address address)
 {
     using (var context = new PunchClockDbContext())
     {
         address.Country = context.Countries.FirstOrDefault(x => x.Id == address.CountryId);
         address.State   = context.States.FirstOrDefault(x => x.Id == address.StateId);
         context.Addresses.Add(address);
         context.SaveChanges();
         return(address.Id);
     }
 }
Beispiel #17
0
 public void Delete(Punch punch)
 {
     using (PunchClockDbContext context = new PunchClockDbContext())
     {
         var updateEntity = context.Punches.FirstOrDefault(x => x.Id == punch.Id);
         if (updateEntity != null)
         {
             context.Punches.Remove(updateEntity);
             context.SaveChanges();
         }
     }
 }
Beispiel #18
0
 public TicketComment Add(TicketComment comment)
 {
     using (var context = new PunchClockDbContext())
     {
         {
             comment.CreatedDateUtc = DateTime.UtcNow;
             context.TicketComments.Add(comment);
             context.SaveChanges();
         }
         return(comment);
     }
 }
Beispiel #19
0
 public void Approve(int id)
 {
     using (PunchClockDbContext context = new PunchClockDbContext())
     {
         var updateEntity = context.Punches.FirstOrDefault(x => x.Id == id);
         if (updateEntity != null)
         {
             updateEntity.Approved = true;
             context.SaveChanges();
         }
     }
 }
Beispiel #20
0
        public ArticleType Add(ArticleType articleType)
        {
            using (var context = new PunchClockDbContext())
            {
                articleType.IsDeleted = false;
                context.ArticleTypes.Add(articleType);
                context.ArticleTypeResources.AddRange(articleType.Resources);
                context.SaveChanges();
            }

            return(articleType);
        }
Beispiel #21
0
 public void SetCreatedBy(int companyId, string userId)
 {
     using (var context = new PunchClockDbContext())
     {
         var company = context.Companies.FirstOrDefault(x => x.Id.Equals(companyId));
         if (company != null)
         {
             company.CreatedById = userId;
         }
         context.SaveChanges();
     }
 }
Beispiel #22
0
        public string PunchOut(int userId, int punchId, TimeSpan punchTime, UserSession session)
        {
            string message = "Successfully punched Out";

            using (PunchClockDbContext context = new PunchClockDbContext())
            {
                var user = context.Users.FirstOrDefault(x => x.Uid == userId);
                if (user == null)
                {
                    return(null);
                }

                var punch = context.Punches.FirstOrDefault(x => x.Id == punchId);
                if (punch == null)
                {
                    return(null);
                }

                if (punch.UserId != userId)
                {
                    return("Invalid operation");
                }

                punch.PunchOut = punchTime != TimeSpan.MinValue ? punchTime : DateTime.Now.ToUniversalTime().TimeOfDay;

                ExplicitPunchTimeCheck(punchTime, punch);

                if (DateTime.UtcNow.Date.Subtract(punch.PunchDate).Days != 0)
                {
                    if (string.IsNullOrEmpty(punch.Comments))
                    {
                        punch.Comments = string.Empty;
                    }
                    message = punch.Comments +=
                        " Due to discrepancy in punch timings, manager Approval is requested for this punch out time";
                    punch.ApprovalRequired = true;
                }
                IpAddressMatchCheck(session.IpAddress, user, punch);
                punch.IpAddress  = session.IpAddress;
                punch.MacAddress = session.MacAddress;
                punch.HostName   = session.HostAddress;
                context.SaveChanges();
            }

            message = string.Format(
                "<div class=\"{0}\">  <button type=\"button\" class=\"close punchCompleteMessage\" onclick=\"punchCompleteMessage();\" data-dismiss=\"alert\">×</button>" +
                message + "</div>",
                message == "Successfully punched Out"
                    ? "alert alert-dismissable alert-success"
                    : "alert alert-dismissable alert-danger");
            return(message);
        }
Beispiel #23
0
 public Ticket Add(Ticket ticket)
 {
     using (PunchClockDbContext context = new PunchClockDbContext())
     {
         if (ticket.DueDateUtc.HasValue)
         {
             ticket.DueDateUtc = ticket.DueDateUtc.Value.ToUniversalTime();
         }
         context.Tickets.Add(ticket);
         context.SaveChanges();
     }
     return(ticket);
 }
Beispiel #24
0
 public bool Delete(int id)
 {
     using (PunchClockDbContext context = new PunchClockDbContext())
     {
         var appSetting = context.AppSettings.Where(x => !x.IsDeleted).FirstOrDefault(x => x.Id == id);
         if (appSetting == null)
         {
             return(false);
         }
         appSetting.IsDeleted = true;
         context.SaveChanges();
         return(true);
     }
 }
Beispiel #25
0
 public void Update(Punch punch)
 {
     using (PunchClockDbContext context = new PunchClockDbContext())
     {
         var updateEntity = context.Punches.FirstOrDefault(x => x.Id == punch.Id);
         if (updateEntity != null)
         {
             updateEntity.PunchDate = punch.PunchDate;
             updateEntity.PunchIn   = punch.PunchIn;
             updateEntity.PunchOut  = punch.PunchOut;
             context.SaveChanges();
         }
     }
 }
Beispiel #26
0
 public void Update(SiteMap siteMap)
 {
     using (var context = new PunchClockDbContext())
     {
         var entity = context.SiteMaps.FirstOrDefault(x => x.Id == siteMap.Id);
         if (entity == null)
         {
             return;
         }
         entity.Name            = siteMap.Name;
         entity.ModifiedDateUtc = DateTime.UtcNow;
         context.SaveChanges();
     }
 }
Beispiel #27
0
 public void Delete(TicketPriority priority)
 {
     using (var context = new PunchClockDbContext())
     {
         var ticketPriority = context.TicketPriorities.FirstOrDefault(x => x.Id == priority.Id);
         if (ticketPriority == null)
         {
             return;
         }
         ticketPriority.ModifiedById    = priority.ModifiedById;
         ticketPriority.ModifiedDateUtc = DateTime.UtcNow;
         ticketPriority.IsDeleted       = true;
         context.SaveChanges();
     }
 }
Beispiel #28
0
 private static void UpdatePassword(string userName, string newPassword, string macAddress, string ipAddress)
 {
     using (PunchClockDbContext context = new PunchClockDbContext())
     {
         var user = context.Users.FirstOrDefault(
             x => x.UserName.Equals(userName, StringComparison.OrdinalIgnoreCase));
         if (user != null)
         {
             user.PasswordHash         = PasswordService.EncodePassword(newPassword, user.PasswordSalt);
             user.LastActiveMacAddress = macAddress;
             user.LastActivityIp       = ipAddress;
             context.SaveChanges();
         }
     }
 }
Beispiel #29
0
 public int Add(Company company)
 {
     using (var context = new PunchClockDbContext())
     {
         if (context.Companies.Any(x => x.Name.Equals(company.Name, StringComparison.OrdinalIgnoreCase)))
         {
             return((int)RegistrationStatus.DuplicateCompany);
         }
         //company.RegisterCode = new Helper.Common.Get().RandomNumber().ToString();
         company.IsActive = false; // SuperAdmin needs to monitor and  activate
         context.Companies.Add(company);
         context.SaveChanges();
         return(company.Id);
     }
 }
Beispiel #30
0
 public void Delete(TicketStatus status)
 {
     using (var context = new PunchClockDbContext())
     {
         var ticketStatus = context.TicketStatuses.FirstOrDefault(x => x.Id == status.Id);
         if (ticketStatus == null)
         {
             return;
         }
         ticketStatus.ModifiedById    = status.ModifiedById;
         ticketStatus.ModifiedDateUtc = DateTime.UtcNow;
         ticketStatus.IsDeleted       = true;
         context.SaveChanges();
     }
 }