Пример #1
0
        //Update VotingCard
        public JsonResult Vote(VotingCardDto votingCardDto)
        {
            object result     = null;
            var    votingCard = _context.VotingCards
                                .Include("VotingCardLines").Where(v => v.Id == votingCardDto.Id).FirstOrDefault();

            if (votingCard == null)
            {
                throw new InvalidOperationException();
            }

            //Validate VotingCardVM on server here

            try
            {
                var votingCardLines = VotingCardHelper.ToVotingCardLines(votingCardDto.VotingCardLines);
                votingCard.Vote(votingCardDto.IsInvalid, votingCardLines);
                _context.SaveChanges();

                var returnedObj = new { AmtAlreadyVoted = votingCard.AmtAlreadyVoted };
                result = new { Status = true, Message = "", ReturnedObj = returnedObj };
            }
            catch (Exception ex)
            {
                result = new { Status = false, Message = ex.Message };
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        public ActionResult SaveAFileToDB(HttpPostedFileBase upload)
        {
            if (upload != null && upload.ContentLength > 0)
            {
                try
                {
                    var file = new CandidateFile
                    {
                        FileType    = FileType.Picture,
                        FileName    = upload.FileName,
                        CandidateId = 1,
                        ContentType = ""
                    };
                    using (var reader = new System.IO.BinaryReader(upload.InputStream))
                    {
                        file.Content = reader.ReadBytes(upload.ContentLength);
                    }

                    _ctx.CandidateFiles.Add(file);
                    _ctx.SaveChanges();
                }
                catch (Exception)
                {
                    //
                }
            }

            return(RedirectToAction("SaveAFileToDB"));
        }
Пример #3
0
        public HttpResponseMessage Post([FromBody] ShareHolder shareHolder)
        {
            //Validate and returnn errors if any
            var response    = new HttpResponseMessage();
            var brokerRules = _shareHolderValidator.BrokenRules(shareHolder);

            if (brokerRules.Count() > 0)
            {
                var message = CoreHelper.MergeErrors(brokerRules);
                response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, message);
                return(response);
            }

            //Persist
            try
            {
                _context.ShareHolders.Add(shareHolder);
                _context.SaveChanges();
                response = Request.CreateResponse <ShareHolder>(HttpStatusCode.Created, shareHolder);
                response.Headers.Location = new Uri(Request.RequestUri, "/Api/ShareHolderDS/" + shareHolder.ShareHolderId.ToString());
            }
            catch (Exception ex)
            {
                response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message, ex);
            }
            return(response);
        }
Пример #4
0
        public Result <int> Create(StatementDto vm)
        {
            var entity = new Statement(vm.Description);

            try
            {
                _context.Statements.Add(entity);
                _context.SaveChanges();
                return(Result.OK <int>(entity.Id));
            }
            catch (Exception ex)
            {
                return(Result.Fail <int>(ex.Message));
            }
        }
Пример #5
0
        public void GenerateVotingByHands()
        {
            RemoveVotingByHands();
            var shareHolders = _context.ShareHolders
                               .Where(m => m.StatusAtMeeting != StatusAtMeeting.Absent)
                               .ToList();

            var statements = _context.Statements.ToList();

            foreach (var sh in shareHolders)
            {
                CreateVotingByHand(sh, statements);
            }

            _context.SaveChanges();
        }
Пример #6
0
        public void ChangeShareHolderStatus(int shareHolderId, int newStatus)
        {
            ShareHolder sh = _context.ShareHolders
                             .Include("VotingCards")
                             .Include("VotingByHands")
                             .Where(s => s.ShareHolderId == shareHolderId)
                             .FirstOrDefault();
            var newStatusInEnum = (StatusAtMeeting)newStatus;

            if (sh == null || sh.StatusAtMeeting == newStatusInEnum)
            {
                return;
            }

            if ((sh.StatusAtMeeting == StatusAtMeeting.Attended && newStatusInEnum == StatusAtMeeting.Delegated) ||
                sh.StatusAtMeeting == StatusAtMeeting.Delegated && newStatusInEnum == StatusAtMeeting.Attended)
            {
                sh.StatusAtMeeting = newStatusInEnum;
                _context.SaveChanges();
                return;
            }

            //Update Status
            sh.StatusAtMeeting = newStatusInEnum;
            StatusAtMeeting newStateInEnum = (StatusAtMeeting)newStatus;

            switch (newStateInEnum)
            {
            case StatusAtMeeting.Absent:
                //sh.RemoveAllVotingCardsAndVotingByHands();
                _context.RemoveVotingCardsAndVotingByHands(sh.ShareHolderId);
                break;

            case StatusAtMeeting.Attended:
                CreateVotingCardsAndVotingByHands(sh);
                break;

            case StatusAtMeeting.Delegated:
                CreateVotingCardsAndVotingByHands(sh);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            _context.SaveChanges();
        }
Пример #7
0
        public Result <Candidate> Handler(RemoveCandidateCommand cmd)
        {
            var id        = cmd.CandidateId;
            var candidate = _context.Candidates.Find(id);

            if (candidate == null)
            {
                return(Result <Candidate> .Fail <Candidate>($"Candidate with id of {id} not found"));
            }
            try
            {
                _context.Candidates.Remove(candidate);
                _context.SaveChanges();
                return(Result <Candidate> .OK <Candidate>(candidate));
            }
            catch (Exception ex)
            {
                return(Result <Candidate> .Fail <Candidate>(ex.Message));
            }
        }
Пример #8
0
 public void SaveToLogTable(string message)
 {
     _ctx.ExceptionLogs.Add(new ExceptionLog(message));
     _ctx.SaveChanges();
 }
Пример #9
0
 public void Commit()
 {
     context.SaveChanges();
 }