public void UpdateWall(WallUpdateModel wall, string userId) { var theWall = _wallRepository.Get(wall.WallId); if (theWall != null) { if (theWall.SiteId != wall.SiteId) { throw new LynexException(string.Format("Wall {0} does not belong to Site {1}", wall.WallId, wall.SiteId)); } if (theWall.Site.UserId != userId) { throw new LynexException(string.Format("User {0} does not have permission on Wall {1}", userId, wall.WallId)); } theWall.X = wall.X; theWall.Y = wall.Y; theWall.Length = wall.Length; theWall.Angle = wall.Angle; theWall.Type = wall.Type; _wallRepository.UpdateWall(theWall); _wallRepository.Save(); } else { throw new LynexException(string.Format("Wall {0} does not exist", wall.WallId)); } }
public IHttpActionResult CreateWall(WallUpdateModel model) { var result = _wallService.CreateWall(model); var obj = new { Success = true, Message = "", Result = result, }; return(Ok(obj)); }
public WallViewModel CreateWall(WallUpdateModel wall) { var theWall = new Wall(); theWall.X = wall.X; theWall.Y = wall.Y; theWall.Length = wall.Length; theWall.Angle = wall.Angle; theWall.Type = wall.Type; theWall.CreatedDateTime = DateTime.UtcNow; theWall.UpdatedDateTime = DateTime.UtcNow; return(new WallViewModel(_wallRepository.AddWall(theWall, wall.SiteId))); }
public IHttpActionResult DeleteWall(WallUpdateModel model) { _wallService.DeleteWall(model, User.Identity.GetUserId()); var result = _siteService.GetSite(model.SiteId, User.Identity.GetUserId()); var obj = new { Success = true, Message = "", Result = result }; return(Ok(obj)); }
public IHttpActionResult UpdateWall(WallUpdateModel model) { _wallService.UpdateWall(model, User.Identity.GetUserId()); return(Ok()); }
public IHttpActionResult SaveMap(SiteViewModel model) { foreach (var wall in model.WallViewModels) { if (wall.IsDirty) { if (!wall.IsDelete) { if (wall.Id != null) { if (!wall.Length.Equals(0)) { _wallService.UpdateWall( new WallUpdateModel { Angle = wall.Angle, Length = wall.Length, SiteId = wall.SiteId, WallId = wall.Id, X = wall.X, Y = wall.Y, Type = wall.Type, }, User.Identity.GetUserId()); } else { var deleteModel = new WallUpdateModel { SiteId = wall.SiteId, WallId = wall.Id }; _wallService.DeleteWall(deleteModel, User.Identity.GetUserId()); } } else if (wall.Length > 0) { _wallService.CreateWall(new WallUpdateModel { Angle = wall.Angle, Length = wall.Length, SiteId = wall.SiteId, WallId = wall.Id, X = wall.X, Y = wall.Y, Type = wall.Type, }); } } else { if (wall.Id != null) { var deleteModel = new WallUpdateModel { SiteId = wall.SiteId, WallId = wall.Id }; _wallService.DeleteWall(deleteModel, User.Identity.GetUserId()); } } } } var result = _siteService.GetSite(model.Id, User.Identity.GetUserId()); var obj = new { Success = true, Message = "", Result = result }; return(Ok(obj)); }