Exemplo n.º 1
0
        public string Post([FromBody] HugModel model)
        {
            //_logger.Log("Post Started");

            var hugs  = _dbService.GetHugs();
            int exist = hugs.Where(x => x.Id == model.Id).Count();

            if (exist == 0)
            {
                Hug newHug = new Hug();
                newHug.Id      = model.Id;
                newHug.To      = model.To;
                newHug.From    = model.From;
                newHug.Reason  = model.Reason;
                newHug.Created = model.Created;

                _dbService.AddHug(newHug);

                return("Hug added");
            }
            else
            {
                return("Hug exists already");
            }
        }
Exemplo n.º 2
0
        public string Patch([FromBody] HugModel model)
        {
            //_logger.Log("Patch Started");

            var hugs    = _dbService.GetHugs();
            int isthere = hugs.Where(x => x.Id == model.Id).Count();

            if (isthere == 1)
            {
                Hug exists = hugs.Find(x => x.Id == model.Id);
                if (!CheckNullOrEmpty(model.Reason))
                {
                    exists.Reason = model.Reason;
                }
                if (!CheckNullOrEmpty(model.To))
                {
                    exists.To = model.To;
                }
                if (!CheckNullOrEmpty(model.From))
                {
                    exists.From = model.From;
                }
                if (!CheckNullOrEmpty(model.Created))
                {
                    exists.Created = model.Created;
                }

                return("Hug updated");
            }
            else
            {
                return("Hug does not exist that you want to update");
            }
        }
Exemplo n.º 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            Hug hug = db.Hugs.Find(id);

            db.Hugs.Remove(hug);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
 public ActionResult Edit([Bind(Include = "HugId,Hugee,HugTypeId,HugDate")] Hug hug)
 {
     if (ModelState.IsValid)
     {
         db.Entry(hug).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.HugTypeId = new SelectList(db.HugTypes, "HugTypeId", "HugType1", hug.HugTypeId);
     return(View(hug));
 }
Exemplo n.º 5
0
        public ActionResult Create([Bind(Include = "HugId,Hugee,HugTypeId,HugDate")] Hug hug)
        {
            if (ModelState.IsValid)
            {
                db.Hugs.Add(hug);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.HugTypeId = new SelectList(db.HugTypes.OrderBy(a => a.HugType1), "HugTypeId", "HugType1", hug.HugTypeId);
            return(View(hug));
        }
Exemplo n.º 6
0
        public void SendHug(UserAccessToken userAccessToken, string recipientUserId)
        {
            _logger.Info("Sending hug from: " + userAccessToken.Email + " to " + recipientUserId);
            var hug = new Hug()
                          {
                              Created = DateTime.Now,
                              SenderID = userAccessToken.Ticket
                          };

            var mongoHug = Mapper.Map<Data.MongoDB.Model.Hug>(hug);
            _hugRepository.InsertHug(recipientUserId, mongoHug);
        }
Exemplo n.º 7
0
        public void Put([FromBody] HugModel model)
        {
            var newHug = new Hug
            {
                From    = model.From,
                To      = model.To,
                Reason  = model.Reason,
                Created = model.Created,
                Id      = model.Id
            };

            _dbManeger.PutHug(newHug);
        }
Exemplo n.º 8
0
        public void SendHug(UserAccessToken userAccessToken, string recipientUserId)
        {
            _logger.Info("Sending hug from: " + userAccessToken.Email + " to " + recipientUserId);
            var hug = new Hug()
            {
                Created  = DateTime.Now,
                SenderID = userAccessToken.Ticket
            };

            var mongoHug = Mapper.Map <Data.MongoDB.Model.Hug>(hug);

            _hugRepository.InsertHug(recipientUserId, mongoHug);
        }
Exemplo n.º 9
0
        public void Post([FromBody] HugModel model)
        {
            _logger.Log("Post started");
            var mappedHug = new Hug
            {
                Id      = model.Id,
                From    = model.From,
                To      = model.To,
                Reason  = model.Reason,
                Created = model.Created
            };

            _dbManager.InsertHug(mappedHug);
        }
Exemplo n.º 10
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Hug hug = db.Hugs.Find(id);

            if (hug == null)
            {
                return(HttpNotFound());
            }
            return(View(hug));
        }
Exemplo n.º 11
0
        // GET: Hugs/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Hug hug = db.Hugs.Find(id);

            if (hug == null)
            {
                return(HttpNotFound());
            }
            ViewBag.HugTypeId = new SelectList(db.HugTypes, "HugTypeId", "HugType1", hug.HugTypeId);
            return(View(hug));
        }
Exemplo n.º 12
0
        public void InsertHug(string recipient, Hug hug)
        {
            var mongUserObject = _mongoCollection.AsQueryable().Single(a => a.UserID == new BsonObjectId(recipient));
            var hugs           = mongUserObject.Hugs;

            if (hugs.Any(a => a.SenderID == hug.SenderID)) //No reason to store this - the user has already hugged.
            {
                return;
            }

            hugs.Add(hug);

            var query  = Query.EQ("_id", new BsonObjectId(recipient));
            var update = Update.AddToSet("Hugs", hug.ToBsonDocument());

            _mongoCollection.FindAndModify(query, SortBy.Null, update);
        }
Exemplo n.º 13
0
        public string Put([FromBody] HugModel model)
        {
            //_logger.Log("Put Started");

            var hugs    = _dbService.GetHugs();
            int isthere = hugs.Where(x => x.Id == model.Id).Count();

            if (isthere == 1)
            {
                Hug exists = hugs.Find(x => x.Id == model.Id);
                exists.Reason  = model.Reason;
                exists.To      = model.To;
                exists.From    = model.From;
                exists.Created = model.Created;

                return("Hug updated");
            }
            else
            {
                return("Hug does not exist that you want to update");
            }
        }