public IActionResult Star(StarDto dto) { var userId = User.GetUserId(); var shelf = _context.Shelves.Include(s => s.CreatedBy).FirstOrDefault(s => s.Id == dto.ShelfId); if (shelf == null) { return(NotFound(nameof(shelf))); } var star = _context.Stars.FirstOrDefault(a => a.UserId == userId && a.ShelfId == shelf.Id); string result; if (star == null) { _context.Stars.Add(shelf.Star(userId)); result = "starred"; } else { _context.Stars.Remove(star); result = "unstarred"; } _context.SaveChanges(); return(Ok(result)); }
private static void ImportStarToDatabase(StarDto starDto) { var db = new MassDefectDatabaseContext(); if (starDto == null) { throw new ArgumentNullException("Star cannot be null!"); } else if (starDto.Name == null) { throw new ArgumentNullException("StarName cannot be null!"); } else if (starDto.SolarSystem == null) { throw new ArgumentNullException("SolarSystem cannot be null!"); } var solarSystem = db.SolarSystems.FirstOrDefault(s => s.Name == starDto.SolarSystem); if (solarSystem == null) { throw new ArgumentNullException("Solar system doesn't exists!"); } var newStar = new Star() { Name = starDto.Name, SolarSystem = solarSystem }; db.Stars.Add(newStar); db.SaveChanges(); }
public async Task <IActionResult> Post([FromBody] StarDto star) { if (!ModelState.IsValid) { return(BadRequest()); } star.Id = 0; var job = await _jobService.CreateStarJobAsync(_mapper.Map <Star>(star)); return(AcceptedAtAction("Get", "Jobs", new { id = job.Id })); }
public IHttpActionResult GetStarByClass(int classID, int attributeID) { int currentMonth = DateTime.Today.Month; int currentYear = DateTime.Today.Year; int daysInMonth = DateTime.DaysInMonth(currentYear, currentMonth); DateTime firstDate = Convert.ToDateTime(currentYear.ToString() + "/" + currentMonth.ToString() + "/01"); DateTime lastDate = Convert.ToDateTime(currentYear.ToString() + "/" + currentMonth.ToString() + "/" + daysInMonth.ToString()); List <StarDto> lstStarData = new List <StarDto>(); for (int iday = 1; iday <= daysInMonth; iday++) { StarDto objStarDto = new StarDto(); objStarDto.day = iday; var performanceCounts = _unitOfWork.PerformancesCount.GetPerformanceCountsByClassAndParameter(classID, attributeID, Convert.ToDateTime(currentYear.ToString() + "/" + currentMonth.ToString() + "/" + iday.ToString())); int totalCount = performanceCounts.Count(); if (totalCount > 0) { int positiveCount = performanceCounts.Where(p => p.Point == true).Count(); decimal percent = (positiveCount * 100) / totalCount; ParameterAttribute attribute = _unitOfWork.ParameterAttributes.GetParameterAttribute(attributeID); if (percent >= attribute.GreenVal) { objStarDto.colorHexCode = "#7CFC00"; } else if (percent >= attribute.YellowVal) { objStarDto.colorHexCode = "#DAA520"; } else { objStarDto.colorHexCode = "#8B0000"; } } else { objStarDto.colorHexCode = "#87ceeb"; } lstStarData.Add(objStarDto); } if (daysInMonth != 31) { for (int iDay = 1; iDay <= (31 - daysInMonth); iDay++) { StarDto objStarDto = new StarDto(); objStarDto.day = daysInMonth + iDay; objStarDto.colorHexCode = "#87ceeb"; lstStarData.Add(objStarDto); } } return(Ok(lstStarData)); }
public IActionResult Delete(StarDto star) { var result = Mapper.Map <Star>(star); _starRepository.Delete(result); if (!_starRepository.Save()) { return(StatusCode(500, "A problem happened while saving the changes")); } return(Ok()); }
public IStarDto GetStarById(int starId) { Star star = this.unitOfWork.StarsDbRepository.Find(starId); IStarDto starDto = new StarDto() { Id = star.Id, Name = star.Name, SollarSystemId = star.SollarSystemId }; return(starDto); }
public static StarDto CreateStar(int randomValue) { var rand = new Random(randomValue * Settings.Seed); var value = rand.Next() % (_modulo * 10); var mass = Settings.StarMassMinimum + (value * _modulo * 10) / (Settings.StarMassMaximum - Settings.StarMassMinimum); value = rand.Next() % (_modulo * 10); var radius = Settings.StarRadiusMinimum + (value * _modulo * 10) / (Settings.StarRadiusMaximum - Settings.StarRadiusMinimum); var star = new StarDto { Mass = mass, Radius = radius, Temperature = Calculate.CalculateStarTemeperature(Settings, mass, radius) }; return(star); }
public IActionResult Create([FromBody] StarDto star) { var result = Mapper.Map <Star>(star); var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(result.FirstName + ' ' + result.LastName); var password = System.Convert.ToBase64String(plainTextBytes); result.Password = password; _starRepository.Create(result); if (!_starRepository.Save()) { return(StatusCode(500, "A problem happened while saving the changes")); } return(Ok()); }
public IEnumerable <IStarDto> GetStarsByName(string starName) { IList <Star> stars = this.unitOfWork.StarsDbRepository.GetAll(s => s.Name == starName).ToList(); IList <IStarDto> starDtos = new List <IStarDto>(stars.Count); foreach (Star star in stars) { IStarDto starDto = new StarDto() { Id = star.Id, Name = star.Name, SollarSystemId = star.SollarSystemId }; starDtos.Add(starDto); } return(starDtos); }
public static void ImportStars() { XDocument xmlDoc = LoadXmlFile("stars"); var stars = xmlDoc.Root.Elements(); List <StarDto> starsDto = new List <StarDto>(); foreach (XElement star in stars) { var starDto = new StarDto() { Name = star.Element("Name")?.Value, Temperature = star.Element("Temperature")?.Value, StarSystem = star.Element("StarSystem")?.Value }; starsDto.Add(starDto); } StarStore.AddStars(starsDto); }
public IActionResult StarAdd(StarDto model) { var currentUserId = User.FindFirst(ClaimTypes.NameIdentifier).Value; var star = _starService.Get(i => i.UserId == Guid.Parse(currentUserId) && i.PostId == model.PostId); var post = _postService.GetById(model.PostId); if (star == null) { post.StarGivenUserCount += 1; post.SumStar += model.RateNumber; post.Star = post.SumStar / post.StarGivenUserCount; _postService.Update(post); _starService.Add(new Star { Id = new Guid(), PostId = model.PostId, RateNumber = model.RateNumber, UserId = Guid.Parse(currentUserId) }); return(StatusCode(200, "Star Başarılı")); } else { post.SumStar += model.RateNumber - star.RateNumber; post.Star = post.SumStar / post.StarGivenUserCount; _postService.Update(post); star.RateNumber = model.RateNumber; _starService.Update(star); return(StatusCode(201, "Star Güncellendi.")); ; } }