示例#1
0
        public IHttpActionResult PutToDo(int id, ToDo toDo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != toDo.Id)
            {
                return(BadRequest());
            }

            db.Entry(toDo).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ToDoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#2
0
        /// <summary>
        /// Add a Project to the Database
        /// </summary>
        /// <param name="project"></param>
        /// <returns></returns>
        public Project AddProject(Project project)
        {
            _context.Projects.Add(project);
            _context.SaveChanges();

            return(project);
        }
示例#3
0
        public void AddUser(User user)
        {
            var crypto = new CryptographyService();
            var salt   = crypto.GenerateSalt();

            user.password = crypto.CalculateHash(salt, user.password);
            user.Salt     = salt;
            user.isActive = true;
            // This is a temp fix for users not being able to register (fix this properly by changing the id type to a GUID)
            user.userID = _timeTrackerContext.Users.Max(user => user.userID) + 1;
            _timeTrackerContext.Users.Add(user);
            _timeTrackerContext.SaveChanges();
        }
示例#4
0
        public bool SaveTime(TimeCard timecard)
        {
            var time = _context.TimeCards
                       .FirstOrDefault(t => t.timeslotID == timecard.timeslotID);

            DateTimeOffset after  = DateTimeOffset.Parse(time.createdOn.ToString());
            DateTimeOffset before = after.AddDays(-7);

            // Get the current date. Minus 2 weeks ago.
            DateTime cutOffDay    = DateTime.Today.AddDays(-14);
            int      cutOffResult = DateTime.Compare(cutOffDay, timecard.timeIn);


            if (cutOffResult > 0)
            {
                //DialogResult res = MessageBox.Show("Are you sure you want to Delete", "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                //if (res == DialogResult.OK)
                //{
                //    MessageBox.Show("You have clicked Ok Button");
                //    //Some task…
                //}
                //if (res == DialogResult.Cancel)
                //{
                //    MessageBox.Show("You have clicked Cancel Button");
                //    //Some task…
                //}
                return(false);
            }

            if (after < before)
            {
                time.isEdited = true;
            }

            time.timeIn      = timecard.timeIn;
            time.timeOut     = timecard.timeOut;
            time.description = timecard.description;

            try
            {
                _context.TimeCards.Update(time);
                _context.SaveChanges();
            }
            catch (DbUpdateException exc)
            {
                Console.WriteLine(exc.InnerException.Message);
                return(false);
            }

            return(true);
        }
示例#5
0
        /// <summary>
        /// Updates the entry.
        /// </summary>
        /// <param name="updatedEntry">The updated entry.</param>
        /// <returns>An <see cref="IOpResult" /> object containing data including whether or
        /// not the operation was successful and any error messages.</returns>
        public IOpResult UpdateTimeEntry(TimeEntry updatedEntry)
        {
            var result = new OpResult();

            try
            {
                using (var ctx = new TimeTrackerContext())
                {
                    // Update the object
                    var entry = ctx.TimeEntries.Single(t => t.TimeEntryId == updatedEntry.TimeEntryId);
                    updatedEntry.CreatedAt = entry.CreatedAt;
                    updatedEntry.CreatedBy = entry.CreatedBy;
                    updatedEntry.UserId = entry.UserId;
                    ctx.Entry(entry).CurrentValues.SetValues(updatedEntry);
                    ctx.SaveChanges();

                    // Return success
                    result.IsSuccessful = true;
                    return result;
                }
            }
            catch (Exception ex)
            {
                // Return failure
                result.IsSuccessful = false;
                result.ErrorMessage = ex.Message;
                return result;
            }
        }
示例#6
0
        /// <summary>
        /// Adds the entry.
        /// </summary>
        /// <param name="entryToAdd">The entry to add.</param>
        /// <param name="userId">The user id.</param>
        /// <returns>
        /// An <see cref="IOpResult"/> object containing data including whether or 
        /// not the operation was successful and any error messages.
        /// </returns>
        public IOpResult AddTimeEntry(TimeEntry entryToAdd, string userId)
        {
            var result = new OpResult();

            try
            {
                using (var ctx = new TimeTrackerContext())
                {
                    // Capture the create date/time and user
                    entryToAdd.CreatedAt = DateTime.Now;
                    entryToAdd.CreatedBy = userId;

                    // Add the object
                    ctx.TimeEntries.Add(entryToAdd);
                    ctx.SaveChanges();

                    // Return success
                    result.IsSuccessful = true;
                    return result;
                }
            }
            catch (Exception ex)
            {
                // Return failure
                result.IsSuccessful = false;
                result.ErrorMessage = ex.Message;
                return result;
            }
        }
示例#7
0
        /// <summary>
        /// Deletes the Project.
        /// </summary>
        /// <param name="projectId">The project id.</param>
        /// <returns>An <see cref="IOpResult" /> object containing data including whether or
        /// not the operation was successful and any error messages.</returns>
        public IOpResult DeleteProject(int projectId)
        {
            var result = new OpResult();

            try
            {
                using (var ctx = new TimeTrackerContext())
                {
                    // Delete the object
                    var project = ctx.Projects.First(c => c.ProjectId == projectId);
                    ctx.Projects.Remove(project);
                    ctx.SaveChanges();

                    // Return success
                    result.IsSuccessful = true;
                    return result;
                }
            }
            catch (Exception ex)
            {
                // Return failure
                result.IsSuccessful = false;
                result.ErrorMessage = ex.Message;
                return result;
            }
        }
示例#8
0
        /// <summary>
        /// Updates the Project.
        /// </summary>
        /// <param name="updatedProject">The updated Project.</param>
        /// <returns>An <see cref="IOpResult" /> object containing data including whether or
        /// not the operation was successful and any error messages.</returns>
        public IOpResult UpdateProject(Project updatedProject)
        {
            var result = new OpResult();

            try
            {
                using (var ctx = new TimeTrackerContext())
                {
                    // Update the object
                    var project = ctx.Projects.First(p => p.ProjectId == updatedProject.ProjectId);
                    ctx.Entry(project).CurrentValues.SetValues(updatedProject);
                    ctx.SaveChanges();

                    // Return success
                    result.IsSuccessful = true;
                    return result;
                }
            }
            catch (Exception ex)
            {
                // Return failure
                result.IsSuccessful = false;
                result.ErrorMessage = ex.Message;
                return result;
            }
        }
示例#9
0
        /// <summary>
        /// Adds the Project.
        /// </summary>
        /// <param name="projectToAdd">The Project to add.</param>
        /// <returns>An <see cref="IOpResult" /> object containing data including whether or
        /// not the operation was successful and any error messages.</returns>
        public IOpResult AddProject(Project projectToAdd)
        {
            var result = new OpResult();

            try
            {
                using (var ctx = new TimeTrackerContext())
                {
                    // Add the object
                    ctx.Projects.Add(projectToAdd);
                    ctx.SaveChanges();

                    // Return success
                    result.IsSuccessful = true;
                    return result;
                }
            }
            catch (Exception ex)
            {
                // Return failure
                result.IsSuccessful = false;
                result.ErrorMessage = ex.Message;
                return result;
            }
        }
示例#10
0
        /// <summary>
        /// Updates the client.
        /// </summary>
        /// <param name="updatedClient">The updated client.</param>
        /// <returns>An <see cref="IOpResult" /> object containing data including whether or
        /// not the operation was successful and any error messages.</returns>
        public IOpResult UpdateClient(Client updatedClient)
        {
            var result = new OpResult();

            try
            {
                using (var ctx = new TimeTrackerContext())
                {
                    // Update the object
                    var client = ctx.Clients.First(c => c.ClientId == updatedClient.ClientId);
                    updatedClient.UserId = client.UserId;
                    ctx.Entry(client).CurrentValues.SetValues(updatedClient);
                    ctx.SaveChanges();

                    // Return success
                    result.IsSuccessful = true;
                    return result;
                }
            }
            catch (Exception ex)
            {
                // Return failure
                result.IsSuccessful = false;
                result.ErrorMessage = ex.Message;
                return result;
            }
        }
示例#11
0
        /// <summary>
        /// Deletes the entry.
        /// </summary>
        /// <param name="timeEntryId">The time entry id.</param>
        /// <returns>
        /// An <see cref="IOpResult"/> object containing data including whether or 
        /// not the operation was successful and any error messages.
        /// </returns>
        public IOpResult DeleteTimeEntry(int timeEntryId)
        {
            var result = new OpResult();

            try
            {
                using (var ctx = new TimeTrackerContext())
                {
                    // Delete the object
                    var entry = ctx.TimeEntries.First(e => e.TimeEntryId == timeEntryId);
                    ctx.TimeEntries.Remove(entry);
                    ctx.SaveChanges();

                    // Return success
                    result.IsSuccessful = true;
                    return result;
                }
            }
            catch (Exception ex)
            {
                // Return failure
                result.IsSuccessful = false;
                result.ErrorMessage = ex.Message;
                return result;
            }
        }
示例#12
0
        /// <summary>
        ///     Updates the billing term.
        /// </summary>
        /// <param name="updatedTerm">The updated term.</param>
        /// <returns>
        ///     An <see cref="IOpResult" /> object containing data including whether or
        ///     not the operation was successful and any error messages.
        /// </returns>
        public IOpResult UpdateBillingTerm(BillingTerm updatedTerm)
        {
            var result = new OpResult();

            try
            {
                using (var ctx = new TimeTrackerContext())
                {
                    // Update the object
                    var existingEntity = ctx.BillingTerms.First(b => b.BillingTermsId == updatedTerm.BillingTermsId);
                    ctx.Entry(existingEntity).CurrentValues.SetValues(updatedTerm);
                    ctx.SaveChanges();

                    // Return success
                    result.IsSuccessful = true;
                    return(result);
                }
            }
            catch (Exception ex)
            {
                // Return failure
                result.IsSuccessful = false;
                result.ErrorMessage = ex.Message;
                return(result);
            }
        }
示例#13
0
        /// <summary>
        ///     Adds the billing term to the database.
        /// </summary>
        /// <param name="termToAdd">The term to add.</param>
        /// <returns>
        ///     An <see cref="IOpResult" /> object containing data including whether or
        ///     not the operation was successful and any error messages.
        /// </returns>
        public IOpResult AddBillingTerm(BillingTerm termToAdd)
        {
            var result = new OpResult();

            try
            {
                using (var ctx = new TimeTrackerContext())
                {
                    // Add the object
                    ctx.BillingTerms.Add(termToAdd);
                    ctx.SaveChanges();

                    // Return success
                    result.IsSuccessful = true;
                    return(result);
                }
            }
            catch (Exception ex)
            {
                // Return failure
                result.IsSuccessful = false;
                result.ErrorMessage = ex.Message;
                return(result);
            }
        }
示例#14
0
        /// <summary>
        /// Deletes the billing term.
        /// </summary>
        /// <param name="deletedTermId">The deleted term id.</param>
        /// <returns>An <see cref="IOpResult" /> object containing data including whether or
        /// not the operation was successful and any error messages.</returns>
        public IOpResult DeleteBillingTerm(int deletedTermId)
        {
            var result = new OpResult();

            try
            {
                using (var ctx = new TimeTrackerContext())
                {
                    // Delete the object
                    var term = ctx.BillingTerms.First(t => t.BillingTermsId == deletedTermId);
                    ctx.BillingTerms.Remove(term);
                    ctx.SaveChanges();

                    // Return success
                    result.IsSuccessful = true;
                    return(result);
                }
            }
            catch (Exception ex)
            {
                // Return failure
                result.IsSuccessful = false;
                result.ErrorMessage = ex.Message;
                return(result);
            }
        }
示例#15
0
        /// <summary>
        /// Saves the profile.
        /// </summary>
        /// <param name="updatedProfile">The updated profile.</param>
        /// <returns>OpResult.</returns>
        public OpResult SaveProfile(UserProfile updatedProfile)
        {
            var result = new OpResult();

            try
            {
                using (var ctx = new TimeTrackerContext())
                {
                    // Get the User profile
                    var profile = ctx.UserProfiles.FirstOrDefault(p => p.UserId.Equals(updatedProfile.UserId));

                    // If there isn't a profile to edit
                    if (profile == null)
                    {
                        // Add the profile
                        ctx.UserProfiles.Add(updatedProfile);
                        ctx.SaveChanges();
                    }
                    else
                    {
                        // Update the object
                        ctx.Entry(profile).CurrentValues.SetValues(updatedProfile);
                        ctx.SaveChanges();
                    }

                    // Return success
                    result.IsSuccessful = true;
                    return result;
                }
            }
            catch (Exception ex)
            {
                // Return failure
                result.IsSuccessful = false;
                result.ErrorMessage = ex.Message;
                return result;
            }
        }
示例#16
0
        public int CreateGroup(Group group)
        {
            try
            {
                _context.Groups.Add(group);
                _context.SaveChanges();
            }
            catch (DbUpdateException exc)
            {
                Console.WriteLine(exc.InnerException.Message);
                return(0);
            }

            return(group.groupID);
        }
示例#17
0
 public void AddUser(User user)
 {
     _context.Users.Add(user);
     _context.SaveChanges();
 }
示例#18
0
 /// <summary>
 /// Adds a course to the database.
 /// </summary>
 /// <param name="course"></param>
 /// <returns></returns>
 public void CreateCourse(Course course)
 {
     _context.Courses.Add(course);
     _context.SaveChanges();
 }