Exemplo n.º 1
0
        public async Task <ResultDto <BaseDto> > DeleteComment(int commentid, ClaimsPrincipal user)
        {
            var result = new ResultDto <BaseDto>()
            {
                Error = null
            };

            //sprawdzam czy uzytkownik istnieje
            string userId = await _userManager.GetId(user);

            var comment = await _commentRepo.GetEntity(x => x.Id == commentid);

            if (comment == null)
            {
                result.Error = "Nie odnaleziono podanego komentarza";
                return(result);
            }

            if (comment.AuthorId != userId)
            {
                result.Error = "Tylko autor może usunąć swój komentarz";
                return(result);
            }

            try
            {
                await _commentRepo.Delete(comment);
            }
            catch (Exception e)
            {
                result.Error = e.Message;
            }

            return(result);
        }
Exemplo n.º 2
0
        //usuwanie recenzji
        public async Task <ResultDto <BaseDto> > DeleteReview(int reviewid, ClaimsPrincipal user)
        {
            var result = new ResultDto <BaseDto>()
            {
                Error = null
            };

            //sprawdzam czy uzytkownik jest wlascicielem recenzji
            string userId = await _userManager.GetId(user);

            var review = await _reviewRepo.GetEntity(x => x.Id == reviewid);

            if (review == null)
            {
                result.Error = "Nie odnaleziono podanej recenzji";
                return(result);
            }

            if (review.UserId != userId)
            {
                result.Error = "Tylko autor może usunąć swoją recenzje";
                return(result);
            }

            try
            {
                await _reviewRepo.Delete(review);
            }
            catch (Exception e)
            {
                result.Error = e.Message;
            }

            return(result);
        }
Exemplo n.º 3
0
        public NoteCatalog Update(NoteCatalog catalog)
        {
            if (catalog == null || !_validator.IsValidEntity(catalog, ProcessResult))
            {
                return(null);
            }

            // check if note render exists in data source
            if (_lookupRepo.GetEntity <NoteRender>(catalog.Render.Id) == null)
            {
                ProcessResult.AddErrorMessage($"Cannot update catalog: {catalog.Name}, because note render does not exists in data source");
                return(null);
            }
            // update catalog record
            var savedCatalog = _dataSource.GetEntity(catalog.Id);

            if (savedCatalog == null)
            {
                ProcessResult.AddErrorMessage($"Cannot update catalog: {catalog.Name}, because system cannot find it in data source");
                return(null);
            }
            var updatedCatalog = _dataSource.Update(catalog);

            if (updatedCatalog == null)
            {
                ProcessResult.PropagandaResult(_dataSource.ProcessMessage);
            }

            return(updatedCatalog);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Details(int Id)
        {
            var mincePie          = _mincePieRepository.GetEntity(m => m.Id == Id);
            var mincePieViewModel = _mapper.Map <MincePieDetailsViewModel>(mincePie);

            mincePieViewModel.ImagePath = await SetupImagePath(mincePie);

            return(View(mincePieViewModel));
        }
        public ActionResult Details(int id)
        {
            Employee employee = _employeeRepository.GetEntity(id);

            if (employee == null)
            {
                return(HttpNotFound());
            }
            return(View(employee));
        }
Exemplo n.º 6
0
        public IActionResult Get(int id)
        {
            Product product = db.GetEntity(id);

            if (product == null)
            {
                return(NotFound());
            }
            return(new ObjectResult(product));
        }
Exemplo n.º 7
0
        public ActionResult Details(int id)
        {
            User user = db.GetEntity(id);

            if (user == null)
            {
                return(HttpNotFound());
            }
            return(View(user));
        }
Exemplo n.º 8
0
        public IActionResult Get(int id)
        {
            MealTime mealTime = db.GetEntity(id);

            if (mealTime == null)
            {
                return(NotFound());
            }
            return(new ObjectResult(mealTime));
        }
Exemplo n.º 9
0
        public IActionResult Get(int id)
        {
            FoodStyle foodStyle = db.GetEntity(id);

            if (foodStyle == null)
            {
                return(NotFound());
            }
            return(new ObjectResult(foodStyle));
        }
        public ActionResult Details(int id)
        {
            var branch = _repository.GetEntity(id);

            if (branch == null)
            {
                return(HttpNotFound());
            }
            return(View(branch));
        }
Exemplo n.º 11
0
        public Propaganda_User ExistUser(Propaganda_User user)
        {
            StringBuilder sb = new StringBuilder("select * from Propaganda_User where 1=1 ");

            if (user.Id > 0)
            {
                sb.Append(" and Id=@Id");
            }
            if (!string.IsNullOrEmpty(user.Account))
            {
                sb.Append(" and Account=@Account");
            }
            if (!string.IsNullOrEmpty(user.WeiXinOpenId))
            {
                sb.Append(" and WeiXinOpenId=@WeiXinOpenId");
            }
            if (!string.IsNullOrEmpty(user.Code))
            {
                sb.Append(" and Code=@Code");
            }
            if (!string.IsNullOrEmpty(user.Name))
            {
                sb.Append(" and Name=@Name");
            }
            if (!string.IsNullOrEmpty(user.QQ))
            {
                sb.Append(" and QQ=@QQ");
            }
            if (!string.IsNullOrEmpty(user.WeiXin))
            {
                sb.Append(" and WeiXin=@WeiXin");
            }
            if (!string.IsNullOrEmpty(user.Address))
            {
                sb.Append(" and Address=@Address'");
            }
            if (!string.IsNullOrEmpty(user.Telephone))
            {
                sb.Append(" and Telephone=@Telephone");
            }
            if (!string.IsNullOrEmpty(user.Email))
            {
                sb.Append(" and Email=@Email");
            }
            if (user.RegisterTime != null)
            {
                sb.Append(" and RegisterTime=@RegisterTime");
            }
            if (user.State != null)
            {
                sb.Append(" and State=@State");
            }
            return(_userDb.GetEntity(sb.ToString(), user));
        }
Exemplo n.º 12
0
        public virtual async Task <IHttpActionResult> Get(int id)
        {
            var entity = await Repository.GetEntity(x => x.Id == id);

            if (entity == null)
            {
                return(NotFound());
            }

            return(Ok(entity));
        }
Exemplo n.º 13
0
        public async Task <IActionResult> GetProduct(int id)
        {
            var product = await _repository.GetEntity(id);

            if (product == null)
            {
                return(NotFound());
            }

            return(Ok(product));
        }
Exemplo n.º 14
0
 /// <summary>
 /// 按照指定标识查找用户
 /// </summary>
 /// <param name="ownerId"></param>
 /// <returns></returns>
 public Api_ClientOwner IsExistOwner(string ownerId = "", string phone = "")
 {
     if (!string.IsNullOrEmpty(ownerId))
     {
         return(_ownerDb.GetEntity(@"select * from Api_ClientOwner where Id=@Id", new { @Id = ownerId }));
     }
     if (!string.IsNullOrEmpty(phone))
     {
         return(_ownerDb.GetEntity(@"select * from Api_ClientOwner where Mobile=@Mobile", new { @Mobile = phone }));
     }
     return(null);
 }
Exemplo n.º 15
0
        public EvevatorConfigDto GetByCommunityId(string communityId)
        {
            var entity = _evevatorConfigRepository.GetEntity(t => t.CommunityUUID == communityId);

            if (entity != null)
            {
                return(entity.ToModel());
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 16
0
        public bool Login(string username, string password)
        {
            var user = _yoneticiRepository.GetEntity().FirstOrDefault(x => x.KullaniciAdi == username && x.Sifre == password);

            if (user == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 17
0
        public IActionResult Get(int id)
        {
            Restaurant restaurant = db.GetEntity(id);

            if (restaurant == null)
            {
                return(NotFound());
            }
            restaurant.City    = restaurant.City;
            restaurant.Country = restaurant.Country;
            restaurant.Streete = restaurant.Streete;
            return(new ObjectResult(restaurant));
        }
Exemplo n.º 18
0
        // GET: Products/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Product product = _repository.GetEntity <Product>(id);

            if (product == null)
            {
                return(HttpNotFound());
            }
            return(View(product));
        }
Exemplo n.º 19
0
        // GET: DrawingResults/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DrawingResult drawingResult = _repository.GetEntity <DrawingResult>(id);

            if (drawingResult == null)
            {
                return(HttpNotFound());
            }
            return(View(drawingResult));
        }
        // GET: Categories/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Category category = _repository.GetEntity <Category>(id);

            if (category == null)
            {
                return(HttpNotFound());
            }
            return(View(category));
        }
Exemplo n.º 21
0
        public List <LevelTransaction> GetLevelTransactions()
        {
            List <LevelTransaction> levelTransaction = new List <LevelTransaction> ();

            try {
                IEnumerable <LevelTransactionDO> levelTransactionDOs = levelTransactionRepository.GetEntities();
                foreach (LevelTransactionDO levelTransDo in levelTransactionDOs)
                {
                    levelTransaction.Add(Converter.GetLevelTransaction(levelTransactionRepository.GetEntity(levelTransDo.ID)));
                }
            } catch (Exception ex) {
                Debug.WriteLine("Exception Occured in GetLevelTransactions method due to " + ex.Message);
            }
            return(levelTransaction);
        }
Exemplo n.º 22
0
        public List <SpaceTransaction> GetSpaceTransactions()
        {
            List <SpaceTransaction> spaceTransaction = new List <SpaceTransaction> ();

            try {
                IEnumerable <SpaceTransactionDO> spaceTransactionDOs = spaceTransactionRepository.GetEntities();
                foreach (SpaceTransactionDO spaceTransDo in spaceTransactionDOs)
                {
                    spaceTransaction.Add(Converter.GetSpaceTransaction(spaceTransactionRepository.GetEntity(spaceTransDo.ID)));
                }
            } catch (Exception ex) {
                Debug.WriteLine("Exception Occured in GetSpaceTransactions method due to " + ex.Message);
            }
            return(spaceTransaction);
        }
Exemplo n.º 23
0
        public async Task <ResultDto <ReviewDto> > GetReview(int reviewid, ClaimsPrincipal user)
        {
            var result = new ResultDto <ReviewDto>()
            {
                Error = null
            };

            //probuje uzyskac wskazana recenzje
            var review = await _reviewRepo.GetEntity(x => x.Id == reviewid);

            if (review == null)
            {
                result.Error = "Nie odnaleziono recenzji";
                return(result);
            }

            //pobieram nazwe uzytkownika
            var loggedInUserId = await _userManager.GetId(user);

            //pobieram nazwe filmu
            var movie = await _movieRepo.GetEntity(x => x.Id == review.MovieId);

            if (movie == null)
            {
                result.Error = "Nie odnaleziono filmu";
                return(result);
            }

            var reviewOwner = await _userManager.FindByIdAsync(review.UserId);

            var reviewOwnerName = reviewOwner.UserName;

            //tworze obiekt z recenzja i zwracam go
            var reviewToSend = new ReviewDto()
            {
                ReviewId  = review.Id,
                Content   = review.Content,
                Rating    = review.Score,
                Author    = reviewOwnerName,
                IsAuthor  = review.UserId == loggedInUserId ? true : false,
                MovieId   = review.MovieId,
                MovieName = movie.Name
            };

            result.SuccessResult = reviewToSend;

            return(result);
        }
Exemplo n.º 24
0
        public Enumerations.AddEntityStatus HandleAssign(int poRequestId, Employee employee, Asset asset, int staffAssignId)
        {
            var poRequest = _poRequestRepository.GetEntity(poRequestId);

            try
            {
                _unitOfWork.BeginTransaction();

                poRequest.RequestStatusID = 5;
                poRequest.FinishedDate    = DateTime.Now.Date;
                _poRequestRepository.UpdateEntity(poRequest);
                _unitOfWork.SaveChanges();

                var history = new History();

                history.Employee            = employee;
                history.Asset               = asset;
                history.Asset.AssetStatusID = 2;
                history.CheckinDate         = DateTime.Now.Date;
                history.StaffAssignID       = staffAssignId;

                AddEntity(history);
                _unitOfWork.SaveChanges();

                _unitOfWork.Commit();

                return(Enumerations.AddEntityStatus.Success);
            }
            catch (Exception e)
            {
                _unitOfWork.Rollback();
            }

            return(Enumerations.AddEntityStatus.Failed);
        }
Exemplo n.º 25
0
        public CouponCode GetUnexpiredCouponCodeById(string id)
        {
            DateTime now        = DateTime.Now;
            var      couponCode = m_counponCodeRespository.GetEntity(x => x.Id == id && now >= x.CreateDate && now < x.EndDate);

            return(couponCode);
        }
Exemplo n.º 26
0
        public void GetEntity_Should_Return_a_Message_by_Message_Id()
        {
            List <Message> list    = _repository.GetList();
            Message        message = _repository.GetEntity(list[0]);

            Assert.That(message.Id, Is.GreaterThan(0));
        }
Exemplo n.º 27
0
        private async Task ProcessMessagesAsync(Message message, CancellationToken token)
        {
            var userAchievement = JsonConvert.DeserializeObject <AchievementUnlockedEvent>(Encoding.UTF8.GetString(message.Body));

            // ********************************************************
            // This would normally use a rules engine of some kind here
            // ********************************************************

            var existingUnlockedAchievement = await _unlockedAchievementsRepository.GetEntity(userAchievement.UserId, userAchievement.Achievement);

            // Only update if it isn't there already, otherwise it would set IsNew = true on existing records
            if (existingUnlockedAchievement == null)
            {
                var newAchievement = new UnlockedAchievementEntity
                {
                    PartitionKey = userAchievement.UserId,
                    RowKey       = userAchievement.Achievement,
                    IsNew        = true
                };

                await _unlockedAchievementsRepository.InsertOrMergeEntity(newAchievement);

                var achievementDetails = await _achievementsRepository.GetEntity("1", newAchievement.RowKey);

                var response = new
                {
                    Name = achievementDetails.RowKey,
                    achievementDetails.Description
                };

                await _hubContext.Clients.User(userAchievement.UserId).SendAsync("Unlocked", response, token);
            }
        }
Exemplo n.º 28
0
        // Delete Department
        public static DepartmentDelete.Response Handle(IRepository repository, DepartmentDelete.Request request)
        {
            var validationDetails = Validator.ValidateRequest(request, repository);

            if (validationDetails.HasValidationIssues)
            {
                return(new DepartmentDelete.Response(validationDetails));
            }

            var department = repository.GetEntity <Department>(
                p => p.DepartmentID == request.CommandModel.DepartmentID,
                new EagerLoadingQueryStrategy <Department>(
                    p => p.Administrator));

            var hasConcurrencyError = false;
            var container           = department.Delete();

            validationDetails = repository.Save(container, dbUpdateConcurrencyExceptionFunc: dbUpdateEx =>
            {
                hasConcurrencyError = true;
                return(new ValidationMessageCollection(new ValidationMessage(string.Empty, dbUpdateEx.ToString())));
            });

            return(new DepartmentDelete.Response(validationDetails, hasConcurrencyError));
        }
Exemplo n.º 29
0
        // GET: Products/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            //1
            if (id == null)
            {
                return(RedirectToAction(nameof(Index)));
            }
            //2
            var product = await repository.GetEntity(id.Value);

            if (product == null)
            {
                return(NotFound());
            }
            //3
            return(View(product));
        }
Exemplo n.º 30
0
 public ActionResult AddToBasket(int?id)
 {
     if (id != null)
     {
         Product product = productRepository.GetEntity(id.Value);
         if (product != null)
         {
             User user = UserManager.FindByName(User.Identity.Name);
             bool isOk = userBasketRepository.AddToBasket(user.BasketId.Value, id.Value);
             if (isOk)
             {
                 return(new RedirectResult("~/Product/GetProduct/" + id.Value));
             }
         }
     }
     return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
 }
        // Modify instructor with course 
        public static InstructorModifyAndCourses.Response Handle(IRepository repository, InstructorModifyAndCourses.Request request)
        {
            var commandModel = request.CommandModel;
            var instructor = repository.GetEntity<Instructor>(
                p => p.ID == commandModel.InstructorId,
                new EagerLoadingQueryStrategy<Instructor>(
                    p => p.Courses,
                    p => p.OfficeAssignment));

            var container = instructor.Modify(repository, request.CommandModel);
            var validationDetails = repository.Save(container);

            return new InstructorModifyAndCourses.Response(validationDetails);
        }
        // Update department
        #region Update department
        public static DepartmentUpdate.Response Handle(IRepository repository, DepartmentUpdate.Request request)
        {
            var validationDetails = Validator.ValidateRequest(request, repository);
            if (validationDetails.HasValidationIssues)
                return new DepartmentUpdate.Response(validationDetails);

            var commandModel = request.CommandModel;
            var currentDept = repository.GetEntity<Department>(
                p => p.DepartmentID == commandModel.DepartmentID,
                new AsNoTrackingQueryStrategy());

            var rowVersion = default(byte[]);
            var container = currentDept.Modify(request.CommandModel);
            validationDetails = repository.Save(container, dbUpdateEx => OnUpdateFailedFunc(repository, dbUpdateEx, commandModel, ref rowVersion));

            return new DepartmentUpdate.Response(validationDetails, rowVersion);
        }
        // Delete instructor
        public static InstructorDelete.Response Handle(IRepository repository, InstructorDelete.Request request)
        {
            var container = new EntityStateWrapperContainer();
            var depts = repository.GetEntities<Department>(p => p.InstructorID == request.CommandModel.InstructorId);
            foreach (var dept in depts)
                container.Add(dept.SetInstructorId(null));

            var deletedInstructor = repository.GetEntity<Instructor>(
                p => p.ID == request.CommandModel.InstructorId,
                new EagerLoadingQueryStrategy<Instructor>(
                    p => p.OfficeAssignment));

            container.Add(deletedInstructor.Delete());
            var validationDetails = repository.Save(container);

            return new InstructorDelete.Response(validationDetails);
        }
        // Delete Department
        public static DepartmentDelete.Response Handle(IRepository repository, DepartmentDelete.Request request)
        {
            var validationDetails = Validator.ValidateRequest(request, repository);
            if (validationDetails.HasValidationIssues)
                return new DepartmentDelete.Response(validationDetails);

            var department = repository.GetEntity<Department>(
                p => p.DepartmentID == request.CommandModel.DepartmentID,
                new EagerLoadingQueryStrategy<Department>(
                    p => p.Administrator));

            var hasConcurrencyError = false;
            var container = department.Delete();
            validationDetails = repository.Save(container, dbUpdateConcurrencyExceptionFunc: dbUpdateEx =>
            {
                hasConcurrencyError = true;
                return new ValidationMessageCollection(new ValidationMessage(string.Empty, dbUpdateEx.ToString()));
            });

            return new DepartmentDelete.Response(validationDetails, hasConcurrencyError);
        }
        private static ValidationMessageCollection OnUpdateFailedFunc(IRepository repository, DbUpdateConcurrencyException dbUpdateEx, DepartmentUpdate.CommandModel commandModel, ref byte[] rowVersion)
        {
            var validationMessages = new ValidationMessageCollection();

            var entry = dbUpdateEx.Entries.Single();
            var databaseEntry = entry.GetDatabaseValues();
            if (databaseEntry == null)
            {
                validationMessages.Add(string.Empty, "Unable to save changes. The department was deleted by another user.");
                return validationMessages;
            }

            var databaseValues = (Department)databaseEntry.ToObject();
            rowVersion = databaseValues.RowVersion;

            if (databaseValues.Name != commandModel.Name)
                validationMessages.Add(nameof(commandModel.Name), "Current value: " + databaseValues.Name);

            if (databaseValues.Budget != commandModel.Budget)
                validationMessages.Add(nameof(commandModel.Budget), "Current value: " + string.Format("{0:c}", databaseValues.Budget));

            if (databaseValues.StartDate != commandModel.StartDate)
                validationMessages.Add(nameof(commandModel.StartDate), "Current value: " + string.Format("{0:d}", databaseValues.StartDate));

            if (databaseValues.InstructorID != commandModel.InstructorID)
                validationMessages.Add(nameof(commandModel.InstructorID), "Current value: " + repository.GetEntity<Instructor>(p => p.ID == databaseValues.InstructorID.Value).FullName);

            validationMessages.Add(string.Empty, "The record you attempted to edit "
                + "was modified by another user after you got the original value. The "
                + "edit operation was canceled and the current values in the database "
                + "have been displayed. If you still want to edit this record, click "
                + "the Save button again. Otherwise click the Back to List hyperlink.");

            return validationMessages;
        }