Exemplo n.º 1
0
        public async Task Save(TimeEntryActivity timeEntryActivity)
        {
            if (_context.Entry(timeEntryActivity).State == EntityState.Detached)
            {
                await _context.TimeEntryActivities.AddAsync(timeEntryActivity);
            }

            await _context.SaveChangesAsync();
        }
        public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            if (dictionary != null)
            {
                var timeEntryActivity = new TimeEntryActivity { Id = dictionary.GetValue<int>("id"), Name = dictionary.GetValue<string>("name"), IsDefault = dictionary.GetValue<bool>("is_default") };
                return timeEntryActivity;
            }

            return null;
        }
        public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            if (dictionary != null)
            {
                var timeEntryActivity = new TimeEntryActivity {
                    Id = dictionary.GetValue <int>("id"), Name = dictionary.GetValue <string>("name"), IsDefault = dictionary.GetValue <bool>("is_default")
                };
                return(timeEntryActivity);
            }

            return(null);
        }
        public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            if (dictionary != null)
            {
                var timeEntryActivity = new TimeEntryActivity
                {
                    Id        = dictionary.GetValue <int>(RedmineKeys.ID),
                    Name      = dictionary.GetValue <string>(RedmineKeys.NAME),
                    IsDefault = dictionary.GetValue <bool>(RedmineKeys.IS_DEFAULT)
                };
                return(timeEntryActivity);
            }

            return(null);
        }
        public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            if (dictionary != null)
            {
                var timeEntryActivity = new TimeEntryActivity
                {
                    Id = dictionary.GetValue<int>(RedmineKeys.ID),
                    Name = dictionary.GetValue<string>(RedmineKeys.NAME),
                    IsDefault = dictionary.GetValue<bool>(RedmineKeys.IS_DEFAULT)
                };
                return timeEntryActivity;
            }

            return null;
        }
Exemplo n.º 6
0
        public async Task <TimeEntry> LogTime(Issue issue, decimal hours, TimeEntryActivity activity, DateTime day, string comments)
        {
            var timeEntry = new TimeEntry
            {
                Project = issue.Project,
                Issue   = new IdentifiableName {
                    Id = issue.Id
                },
                Activity = new IdentifiableName {
                    Id = activity.Id
                },
                Comments = comments,
                SpentOn  = day.Date,
                User     = new IdentifiableName {
                    Id = _user.Id
                },
                Hours = hours
            };
            var savedEntry = await LogTime(timeEntry);

            return(savedEntry);
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Create(
            CancellationToken cancellationToken,
            [FromBody] CreateTimeEntryActivityBinding binding,
            [FromServices] ITimeEntryActivityRepository timeEntryActivityRepository)
        {
            var timeEntryActivity = await timeEntryActivityRepository.Get(binding.Id, cancellationToken);

            if (timeEntryActivity != null)
            {
                if (!timeEntryActivity.Name.Equals(binding.Name))
                {
                    throw new ApiException(HttpStatusCode.Conflict, ErrorCode.TimeEntryActivityAlreadyExists,
                                           "Issue status already exists with other parameters");
                }
            }

            timeEntryActivity = new TimeEntryActivity(binding.Id, binding.Name, binding.IsActive);

            await timeEntryActivityRepository.Save(timeEntryActivity);

            return(CreatedAtRoute("GetTimeEntryActivityAdminRoute", new { id = timeEntryActivity.Id }, null));
        }
        /// <summary>
        /// Method to add time entry in redmine issues
        /// </summary>
        /// <param name="user">user details</param>
        /// <param name="text">list of string containing parameter to add time entry</param>
        private async Task AddTimeEntryToRedmineIssue(ApplicationUser user, List <string> text)
        {
            int    issueId;
            string result;

            if (ToCheckIssueExistOrNot(text[2], user.RedmineApiKey, out issueId, out result))
            {
                double hour;
                var    hourConvertor = double.TryParse(text[3], out hour);
                if (hourConvertor)
                {
                    DateTime date;
                    if (DateTime.TryParseExact(text[4], _stringConstant.RedmineTimeEntryDateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out date))
                    {
                        TimeEntryActivity timeEntryActivity;
                        if (TimeEntryActivity.TryParse(text[5], out timeEntryActivity))
                        {
                            var timeEntry = new RedmineTimeEntryApplicationClass()
                            {
                                TimeEntry = new RedmineTimeEntries()
                                {
                                    ActivityId = timeEntryActivity,
                                    IssueId    = issueId,
                                    Date       = date.ToString(_stringConstant.RedmineTimeEntryDateFormat),
                                    Hours      = hour
                                }
                            };
                            var requestUrl = string.Format(_stringConstant.FirstAndSecondIndexStringFormat,
                                                           _stringConstant.RedmineBaseUrl, _stringConstant.TimeEntryUrl);
                            var jsonText = JsonConvert.SerializeObject(timeEntry);
                            // Post call to add time entry
                            var response = await _httpClientService.PostAsync(requestUrl, jsonText,
                                                                              _stringConstant.JsonApplication, user.RedmineApiKey, _stringConstant.RedmineApiKey);

                            if (!string.IsNullOrEmpty(response))
                            {
                                // If added time entry in redmine issue
                                replyText = string.Format(_stringConstant.TimeEnrtyAddSuccessfully, issueId);
                            }
                            else
                            {
                                // If error in adding time entry in redmine issue
                                replyText = string.Format(_stringConstant.ErrorInAddingTimeEntry, issueId);
                            }
                        }
                        else
                        {
                            // If TimeEntryActivity is not valid
                            replyText = string.Format(_stringConstant.TimeEntryActivityErrorMessage, TimeEntryActivity.Analysis.ToString(),
                                                      TimeEntryActivity.Design.ToString(), TimeEntryActivity.Development.ToString(), TimeEntryActivity.Roadblock.ToString(),
                                                      TimeEntryActivity.Testing.ToString());
                        }
                    }
                    else
                    {
                        // If date format is not valid
                        replyText = string.Format(_stringConstant.DateFormatErrorMessage, _stringConstant.RedmineTimeEntryDateFormat);
                    }
                }
                else
                {
                    // If hour is not in numeric
                    replyText = _stringConstant.HourIsNotNumericMessage;
                }
            }
        }