public static Roaster AddRoasterNullPlugs(Roaster entity)
        {
            if (entity.ContactPersonName == null)
            {
                entity.ContactPersonName = "none";
            }
            if (entity.ContactPersonPhone == null)
            {
                entity.ContactPersonPhone = "none";
            }
            if (entity.ContactEmail == null)
            {
                entity.ContactEmail = "none";
            }
            if (entity.InstagramProfileLink == null)
            {
                entity.InstagramProfileLink = "none";
            }
            if (entity.WebSiteLink == null)
            {
                entity.WebSiteLink = "none";
            }
            if (entity.VkProfileLink == null)
            {
                entity.VkProfileLink = "none";
            }
            if (entity.TelegramProfileLink == null)
            {
                entity.TelegramProfileLink = "none";
            }

            return(entity);
        }
        public async Task <IActionResult> CreateRoaster(Roaster roaster, byte[] picture)
        {
            try
            {
                var roastDate = DateTime.UtcNow;
                var roaster1  = Roaster.New(roaster.ContactPersonName,
                                            roaster.ContactPersonPhone,
                                            roaster.Name,
                                            roaster.ContactNumber,
                                            roaster.ContactEmail,
                                            roaster.WebSiteLink,
                                            roaster.VkProfileLink,
                                            roaster.InstagramProfileLink,
                                            roaster.TelegramProfileLink,
                                            roaster.Description,
                                            roastDate,
                                            roaster.Priority
                                            );
                _roasterRepository.Add(roaster);
                await _roasterRepository.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e.ToString()));
            }
        }
Beispiel #3
0
        public async Task <IActionResult> Edit(int id, [Bind("RoasterId,UserId,Name,City,StateAbbrev,ImagePath")] Roaster roaster)
        {
            if (id != roaster.RoasterId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(roaster);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RoasterExists(roaster.RoasterId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["StateAbbrev"] = new SelectList(_context.State, "StateAbbrev", "StateAbbrev", roaster.StateAbbrev);
            ViewData["UserId"]      = new SelectList(_context.ApplicationUsers, "Id", "Id", roaster.UserId);
            return(View(roaster));
        }
        public async Task <int> AddRoasterAsync(Roaster roaster,
                                                string tags,
                                                Address address,
                                                string latitude,
                                                string longitude,
                                                IFormFile picture)
        {
            try
            {
                _logger.Information("Roaster admin service layer access in progress...");

                var roasterByName = await _roasterRepository.GetRoasterByNameNonTrackableAsync(roaster.Name);

                if (roasterByName != null)
                {
                    return(-1);
                }

                //Get and process tags string into tag entities
                var _localTags = await RoasterAdminServiceBuilder.BuildTagsListAsync(tags,
                                                                                     _tagRepository);

                //process address entity
                var _address = Address.New(address.AddressStr,
                                           address.OpeningHours,
                                           address.Latitude,
                                           address.Longitude);
                address = AddressCoordinatesTransformer.ConvertCoordinates(address, latitude, longitude);
                roaster.OfficeAddress = _address;
                _addressReposiotry.Add(_address);
                //add roasterTags  notes
                RoasterTagsPairsBuilder.BuildRoasterTags(_localTags,
                                                         roaster.Id,
                                                         _roasterTagRepository);

                var pictureBytes = BytePictureBuilder.GetBytePicture(picture);
                BytePictureBuilder.BindPicture(roaster.Id, pictureBytes, _pictureRepository);

                roaster = RoasterAdminServiceBuilder.AddRoasterNullPlugs(roaster);

                _roasterRepository.Add(roaster);
                await _roasterRepository.SaveChangesAsync();

                _logger.Information($"Roaster, Tags, RoasterTags, Addresses tables have been modified. Inserted roaster:\n Id: {roaster.Id}\n Roaster name: {roaster.Name}");
                return(0);
            }
            catch (Exception e)
            {
                _logger.Error($"Roaster admin service layer error occured! Error text message: {e.Message}");
                return(-2);
            }
        }
Beispiel #5
0
        public async Task <IActionResult> Create([Bind("RoasterId,UserId,Name,City,StateAbbrev,ImagePath")] Roaster roaster)
        {
            if (ModelState.IsValid)
            {
                _context.Add(roaster);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["StateAbbrev"] = new SelectList(_context.State, "StateAbbrev", "StateAbbrev", roaster.StateAbbrev);
            ViewData["UserId"]      = new SelectList(_context.ApplicationUsers, "Id", "Id", roaster.UserId);
            return(View(roaster));
        }
Beispiel #6
0
 /// <summary>
 /// Generates Roaster entity brand new id with
 /// </summary>
 /// <param name="roaster"></param>
 /// <param name="addressId"></param>
 /// <returns>Roaster note</returns>
 public static Roaster GenerateRoaster(OwnedRoaster roasterRequest)
 => Roaster.New(roasterRequest.ContactPersonName,
                roasterRequest.ContactPersonNumber,
                roasterRequest.Name,
                roasterRequest.ContactNumber,
                roasterRequest.ContactEmail,
                roasterRequest.WebSiteLink,
                roasterRequest.VkProfileLink,
                roasterRequest.InstagramProfileLink,
                roasterRequest.TelegramProfileLink,
                roasterRequest.Description,
                DateTime.Now,
                roasterRequest.Priority);
        public async Task <IActionResult> UpdateRoaster(Roaster roaster)
        {
            try
            {
                _roasterRepository.Update(roaster);
                await _roasterRepository.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e.ToString()));
            }
        }
Beispiel #8
0
        public async Task <int> UpdateRoasterAsync(Roaster entity)
        {
            try
            {
                _logger.Information("RoasterAddressConnection service layer access in progress...");
                _roasterRepository.Update(entity);
                await _roasterRepository.SaveChangesAsync();

                _logger.Information($"Roaster and Address tables have been modified. Modified roaster:\n {entity.Id}\n Name:{entity.Name}");
                return(0);
            }
            catch (Exception e)
            {
                _logger.Error("Roaster address connection service layer error occured! Error text message:" + e.Message);
                return(-1);
            }
        }
Beispiel #9
0
        public void TestGoodCookingByTimer()
        {
            Roaster roaster = new Roaster(2, 2);

            Assert.IsTrue(roaster.Receive(new Bread(), 0, 0));
            Assert.IsTrue(roaster.Receive(new Bread(), 0, 1));
            roaster.Settimer(0, 5);
            roaster.CloseLever(0);
            System.Threading.Thread.Sleep(MSPERTICK * 11);
            // simulate timeout --> lever auto open
            ItemAbstract item = roaster.Release(0, 0);

            Assert.AreEqual(CookingStatus.Cooked, item.CookingStatus);

            item = roaster.Release(0, 1);
            Assert.AreEqual(CookingStatus.Cooked, item.CookingStatus);
        }
Beispiel #10
0
        public void TestUnderCookingByForceEnded()
        {
            Roaster roaster = new Roaster(2, 2);

            Assert.IsTrue(roaster.Receive(new Bread(), 1, 0));
            Assert.IsTrue(roaster.Receive(new Bagel(), 1, 1));
            roaster.Settimer(1, 10); // 10 ticks
            roaster.CloseLever(1);

            System.Threading.Thread.Sleep(MSPERTICK * 8);
            roaster.OpenLever(1); // simulate force close

            ItemAbstract item = roaster.Release(1, 0);

            Assert.AreEqual(CookingStatus.Over, item.CookingStatus);

            item = roaster.Release(1, 1);
            Assert.AreEqual(CookingStatus.Under, item.CookingStatus);
        }
        public async Task <int> UpdateRoasterAsync(Roaster entity, string tags, string latitude, string longitude, IFormFile picture)
        {
            _logger.Information("Roaster admin service layer access in progress...");
            try
            {
                var broast = await _roasterRepository.GetRoasterByNameNonTrackableAsync(entity.Name);

                if (broast != null && !broast.Id.Equals(entity.Id))
                {
                    return(-1);
                }

                await RoasterAdminServiceBuilder.UpdateRoasterTagsAsync(tags,
                                                                        _tagRepository,
                                                                        _roasterTagRepository,
                                                                        entity.Id);

                await BytePictureBuilder.ReplacePicture(entity.Id, picture, _pictureRepository);


                var roasterAddress = await _addressReposiotry.GetSingleAsync(entity.OfficeAddress.Id);

                entity.OfficeAddress = AddressCoordinatesTransformer.ConvertCoordinates(entity.OfficeAddress, latitude, longitude);
                entity.OfficeAddress = RoasterAdminServiceBuilder.UpdateRoasterAddress(roasterAddress, entity.OfficeAddress);
                _addressReposiotry.Update(entity.OfficeAddress);

                entity = RoasterAdminServiceBuilder.AddRoasterNullPlugs(entity);
                _roasterRepository.Update(entity);
                await _roasterTagRepository.SaveChangesAsync();

                _logger.Information($"Roaster, Tags, RoasterTags, Addresses tables have been modified. Updated roaster:\n Id: {entity.Id}\n Roaster name: {entity.Name}");
                return(0);
            }
            catch (Exception e)
            {
                _logger.Error("Roaster admin service layer error occured! Error text message:" + e.Message);
                return(-2);
            }
        }