Пример #1
0
        // PUT api/Position/5
        public IHttpActionResult PutPosition(int id, Position position)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != position.Id)
            {
                return BadRequest();
            }

            // Ownership reassignment is not allows
            if (position.OwnerIdentity != User.Identity.Name)
                return BadRequest();

            using (var tx = db.BeginTransaction())
            {
                db.SaveOrUpdate(position);
                tx.Commit();
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Пример #2
0
        public ActionResult ImportLinkedIn(ImportLinkedInViewModel importProfile)
        {
            // Update profile values
            var profile = db.Query<Profile>().SingleOrDefault(p => p.OwnerIdentity == User.Identity.Name) ?? new Profile();
            profile.FirstName = importProfile.FirstName;
            profile.LastName = importProfile.LastName;
            profile.Summary = importProfile.Summary;
            profile.OwnerIdentity = User.Identity.Name;

            // Model binder is not reading the positions
            // TODO: Convert to custom model binder
            int i = 0;
            while (true)
            {
                if (i > 99)
                    break;

                var p = string.Format("Positions[{0}]", i);
                var id = Request[p + ".Id"];
                if (id == null)
                    break;

                var position = new Position();
                position.Title = Request[p + ".Title"];
                position.Company = Request[p + ".Company"];
                position.Description = Request[p + ".Description"];
                position.StartDate = DateTime.Parse(Request[p + ".StartDate"]);
                var endDate = Request[p + ".EndDate"];
                if(endDate != null)
                    position.EndDate = DateTime.Parse(Request[p + ".EndDate"]); ;
                importProfile.Positions.Add(position);

                i++;
            }

            using(var tx = db.BeginTransaction())
            {
                db.SaveOrUpdate(profile);

                foreach(var position in importProfile.Positions)
                {
                    position.OwnerIdentity = User.Identity.Name;
                    db.Save(position);
                }

                tx.Commit();
            }

            return View("ImportLinkedInSuccess");
        }
Пример #3
0
        public IHttpActionResult PostPosition(Position position)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            // Ownership reassignment is not allows
            if (position.OwnerIdentity != User.Identity.Name)
                return BadRequest();

            db.Save(position);

            return CreatedAtRoute("DefaultApi", new { id = position.Id }, position);
        }