コード例 #1
0
        /// <summary>
        /// Used to save a timeZone Entry
        /// </summary>
        /// <returns></returns>
        public int SaveTimeZone(TimeZoneEntryModel entry)
        {
            var timeDifferenceSpan = new TimeSpan(entry.HourDifference, entry.MinuteDifference, 0).Ticks;

            if (entry.TimeZoneEntryId != 0)
                return new Data.TimeZoneEntryMethods().ModifyTimeZoneEntry(new TimeZoneEntry
                {
                    City = entry.City,
                    EntryName = entry.EntryName,
                    UserId = entry.UserId,
                    Id = entry.TimeZoneEntryId,
                    Difference = timeDifferenceSpan
                });

            return new Data.TimeZoneEntryMethods().SaveNewTimeZoneEntry(new TimeZoneEntry
            {
                City = entry.City,
                EntryName = entry.EntryName,
                UserId = entry.UserId,
                Difference = timeDifferenceSpan,
                IsActive = true
            });
        }
コード例 #2
0
        public int SaveTimeZone(TimeZoneEntryModel entry)
        {
            try
            {
                if (Math.Abs(entry.HourDifference) > 14 || Math.Abs(entry.MinuteDifference) > 60)
                    throw new HttpResponseException(HttpStatusCode.BadRequest);

                TimeZoneEntryModel entryData = null;

                if (entry.TimeZoneEntryId != 0)
                    entryData = new TimeZoneEntryMethods().GetTimeZoneInformation(entry.TimeZoneEntryId);

                if (entry.TimeZoneEntryId != 0 && entryData == null)
                    throw new EntryNotFound();

                entry.UserId = new UserInformation().GetCurrentUserInformation().UserId;

                if (entry.TimeZoneEntryId != 0 && entryData.UserId != entry.UserId)
                    throw new UnAuthorize("User Not Authorize");

                return new Business.TimeZoneEntryMethods().SaveTimeZone(entry);
            }
            catch (EntryNotFound ex)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content = new StringContent(string.Format("No Entry with ID = {0}", entry.TimeZoneEntryId)),
                    ReasonPhrase = "Entry Not Found"
                });

            }
            catch (HttpResponseException ex)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content = new StringContent(string.Format("HourDifference or Minute Difference not valid.")),
                    ReasonPhrase = "Bad Request"
                });
            }
            catch (UnAuthorize ex)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized)
                {
                    Content = new StringContent(string.Format("You are not authorize.")),
                    ReasonPhrase = "UnAuthorize"
                });
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.ServiceUnavailable)
                {
                    Content = new StringContent(string.Format("Service is currently unavailable.")),
                    ReasonPhrase = "Service Unavailable "
                });
            }
        }