public void Test_WebWeatherBit_GetTempDaysFromWeather_FoundData() { WebWeatherBit oWeather = new WebWeatherBit(); DayTemperature answer = oWeather.GetHistoryTemps("Navojoa", "M"); Assert.IsTrue(answer.date.Length > 0); }
public ActionResult GetDayTemperature(string city, int day, int month, int year) { string dayWeather = JsonConvert.SerializeObject( DayTemperature.GetDayTemperature(city, day, month, year) ); return(Content(dayWeather)); }
public void Test_WebWeatherBit_ConvertStringToJsonObject_WrongNoCity() { WebWeatherBit oWeather = new WebWeatherBit(); DayTemperature answer = oWeather.GetHistoryTemps("guaymas", "M"); Assert.AreNotEqual(0, answer.date.Length); ; }
public ActionResult GetThreeMonthTemperature(string city, int firstMonth, int year) { DateTime date = DateTime.Parse(string.Format("01.{0}.{1}", firstMonth.ToString("d2"), year)).AddMonths(1); Dictionary <string, DayTemperature> dict = new Dictionary <string, DayTemperature>(); foreach (DayTemperature dt in DayTemperature.GetThreeMonthTemperature(city, date.Month, date.Year)) { dict[dt.date.ToString("yyyy-MM-dd")] = dt; } string threeMonthWeather = JsonConvert.SerializeObject(dict); string threeMonthWeatherForCity = "{\"" + city + "\":" + threeMonthWeather + "}"; return(Content(threeMonthWeatherForCity)); }
public ActionResult EditEvent(Event ev, bool ResizeOrDrug = false) { Event editEvent = eventContext.Events.Find(ev.EventId); editEvent.Name = ev.Name; editEvent.StartDate = ev.StartDate; editEvent.EndDate = ev.EndDate; editEvent.Description = ResizeOrDrug ? editEvent.Description : ev.Description; editEvent.Latitude = ev.Latitude ?? editEvent.Latitude; editEvent.IndoorEvent = ResizeOrDrug ? editEvent.IndoorEvent : ev.IndoorEvent; editEvent.Longitude = ev.Longitude ?? editEvent.Longitude; editEvent.WeatherRegion = ev.WeatherRegion ?? editEvent.WeatherRegion; if (editEvent.WeatherRegion != null) { DayTemperature dayTemperature = DayTemperature.GetDayTemperature (editEvent.WeatherRegion, ev.StartDate.Day, ev.StartDate.Month, ev.StartDate.Year); editEvent.WeatherDay = dayTemperature.dayTemp; editEvent.WeatherNight = dayTemperature.nightTemp; editEvent.WeatherType = eventContext.WeatherTypes.Where(i => i.Description == dayTemperature.description).First(); } var userEvents = userEventContext.UserEvents.Where(ue => ue.EventId == ev.EventId).Select(uv => uv); foreach (var userInv in userEvents) { if (userInv.UserId == User.Identity.GetUserId()) { continue; } EmailService es = new EmailService(); IdentityMessage im = new IdentityMessage() { Destination = UsersContext.Users.Find(userInv.UserId).Email, Subject = "Фотосессия в которой вы участвуете, была изменена" }; im.Body = $"Фотосессия \"{ev.Name}\" была изменена! <p> Время начала: {ev.StartDate} </p>" + $"< p > Время конца: { ev.EndDate} </ p > " + $"\n <p>{ev.Description} </p>"; es.SendAsync(im); } eventContext.SaveChanges(); return(Content(ev.EventId.ToString())); }
static void Main(string[] args) { Console.WriteLine(); #region For C# OPERATOR #if false /**Pre- and post increment */ OperatorHolder.PreAndPsotOper(); Console.WriteLine(OperatorHolder.TheTernaryOper(12)); /**The checked and unchecked operator */ OperatorHolder.TheCheckedOper(); OperatorHolder.TheUncheckedoper(); #endif #if false AsAndIsHolder.TheIsOper(); AsAndIsHolder.CreatAvarUsingIsOper(new AsAndIsHolder()); Console.WriteLine(); AsAndIsHolder.TheAsOper(); #endif #if false SizeOfHolder.PrintBytes(); #endif #endregion #region For C# Type safety (Explicit type casting) #if false TypeSafety.TestTypeCasting(); double[] Prices = { 25.30, 26.20, 27.40, 30.00 }; var h = new TypeSafety(); h.Description = "Hello there."; h.ApproxPrice = (int)(Prices[0] + 0.5); Console.WriteLine(h.ApproxPrice); #endif #endregion #region For C# boxing and unboxing #if false BoxUnBox.Test(); #endif #endregion #region For C# COMPARING OBJECTS FOR EQUALITY #if false B.Test(); Point point2D = new Point(5, 5); Point3D point3Da = new Point3D(5, 5, 2); Console.WriteLine("{0} = {1}: {2}", point2D, point3Da, point2D.Equals(point2D)); var a = new StrA(); var b = new StrB(); StrB.ValueTypeComparison(a, b); Console.WriteLine(); #endif #endregion #region For C# arithmetic operators overloading #if false AdditionHolder adh = new AdditionHolder(12, 1.0); Console.WriteLine("The result without operator loading when: AgeDeterminer(13, adh)"); var res = AdditionHolder.AgeDeterminer(13, adh); Console.WriteLine((res.age, res.grownedHeight)); Console.WriteLine("The result with operator loading when: 13 + adh ="); var res2 = 13 + adh; Console.WriteLine((res2.age, res2.grownedHeight)); var thrd1 = new ThreeDMoves(1.0, 2.0, 3.0); var thrd2 = new ThreeDMoves(2.0, 3.0, 4.0); var thrd3 = thrd1 *= 2; var thrd4 = thrd1 * thrd3; Console.WriteLine($"thrd3: {thrd3}\nthrd4: {thrd4}"); #endif #endregion #region For C# Overloading the Comparison Operators #if false var i1 = new DayTemperature(25, 19); var i2 = new DayTemperature(25, 19); var i3 = new DayTemperature(125, 119); DayTemperature.IsTempSame(i1, i1); var resOfEqualOperator = i1 == i2; var resOfNotEqualOperator = i1 != i2; i1.Equals(i2); i1.GetHashCode(); i2.GetHashCode(); i3.GetHashCode(); Console.WriteLine("======================================================================"); DayTemperature.IsTempSame(i1, i3); var resOfEqualOperator1 = i1 == i3; var resOfNotEqualOperato2r = i1 != i3; #endif #endregion #region For C# USER-DEFINED CASTS (implicit and explicit) it's kind like a operator overloading but not really #if true var toBeConverted = new TheDestinationType(101); Console.WriteLine($"The original type of toBeConverted: {toBeConverted.GetType().Name}"); var converted = (TheSourceType)toBeConverted; Console.WriteLine($"The destination type of toBeConverted: {converted.GetType().Name}\n"); Console.WriteLine($"//From *heSourceType type to short "); short shortCasting = (short )converted; Console.WriteLine($"The destination type of shortCasting: {shortCasting.GetType().Name}"); Console.WriteLine($"//From *short type to double "); var shortTodouble = (double)shortCasting; Console.WriteLine($"The destination type of shortTodouble: {shortTodouble.GetType().Name}"); #endif #endregion Console.WriteLine(); }
public ActionResult AddEvent(Event ev, string InvitedUsers) { string currentUser = User.Identity.GetUserId(); if (currentUser != null) { if (ev.WeatherRegion != null) { DayTemperature dayTemperature = DayTemperature.GetDayTemperature (ev.WeatherRegion, ev.StartDate.Day, ev.StartDate.Month, ev.StartDate.Year); ev.WeatherDay = dayTemperature.dayTemp; ev.WeatherNight = dayTemperature.nightTemp; ev.WeatherType = eventContext.WeatherTypes.Where(i => i.Description == dayTemperature.description).First(); } eventContext.Events.Add(ev); eventContext.SaveChanges(); //полуучает объект пользователя по id //ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId()); userEventContext.UserEvents.Add(new UserEvent() { EventId = ev.EventId, UserId = currentUser, CreatorId = currentUser }); string[] invitedUsers = InvitedUsers.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string user in invitedUsers) { string invitedId = UsersContext.Users.Where(u => u.UserName.Equals(user)).Select(id => id.Id).FirstOrDefault(); if (invitedId.Equals(currentUser)) { continue; } userEventContext.UserEvents.Add(new UserEvent() { EventId = ev.EventId, UserId = invitedId, CreatorId = currentUser }); EmailService es = new EmailService(); IdentityMessage im = new IdentityMessage() { Destination = UsersContext.Users.Find(invitedId).Email, Subject = "Вас пригласили на фотосессию" }; im.Body = $"Вас пригласили на фотосессию \"{ev.Name}\"! <p> Время: {ev.StartDate} </p>" + $"< p > Время конца: { ev.EndDate} </ p > " + $"\n <p>{ev.Description} </p>"; es.SendAsync(im); } userEventContext.SaveChanges(); return(Content(ev.EventId.ToString())); } else { return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized)); } }