Esempio n. 1
0
        public void DeleteMediaItem(int userId, int mediaItemId)
        {
            var dataModel = new OCMEntities();

            var item = dataModel.MediaItems.FirstOrDefault(c => c.ID == mediaItemId);

            if (item != null)
            {
                var cpID = item.ChargePointID;
                dataModel.MediaItems.Remove(item);
                dataModel.ChargePoints.Find(cpID).DateLastStatusUpdate = DateTime.UtcNow;
                dataModel.SaveChanges();

                //TODO: delete from underlying storage
                var user = new UserManager().GetUser(userId);
                AuditLogManager.Log(user, AuditEventType.DeletedItem, "{EntityType:\"Comment\", EntityID:" + mediaItemId + ",ChargePointID:" + cpID + "}", "User deleted media item");
            }
        }
Esempio n. 2
0
        public MediaItem AddPOIMediaItem(string tempFolder, string sourceImageFile, int chargePointId, string comment, bool isVideo, int userId)
        {
            var dataModel = new OCMEntities();

            var mediaItem = new MediaItem();

            var poi = new POIManager().Get(chargePointId);
            string[] urls = UploadPOIImageToStorage(tempFolder, sourceImageFile, poi);
            if (urls == null)
            {
                //failed to upload, preserve submission data
                System.IO.File.WriteAllText(tempFolder + "//OCM_" + chargePointId + "_" + (DateTime.Now.ToFileTimeUtc().ToString()) + ".json", "{userId:" + userId + ",comment:\"" + comment + "\"}");
                return null;
            }
            else
            {
                mediaItem.ItemURL = urls[0];
                mediaItem.ItemThumbnailURL = urls[1];

                mediaItem.User = dataModel.Users.FirstOrDefault(u => u.ID == userId);
                mediaItem.ChargePoint = dataModel.ChargePoints.FirstOrDefault(cp => cp.ID == chargePointId);
                mediaItem.Comment = comment;
                mediaItem.DateCreated = DateTime.UtcNow;
                mediaItem.IsEnabled = true;
                mediaItem.IsExternalResource = false;
                mediaItem.IsVideo = isVideo;

                dataModel.MediaItems.Add(mediaItem);

                dataModel.ChargePoints.Find(chargePointId).DateLastStatusUpdate = DateTime.UtcNow;
                dataModel.SaveChanges();

                new UserManager().AddReputationPoints(userId, 1);

                return mediaItem;
            }
        }
        private ActionResult ProcessLoginResult(string userIdentifier, string loginProvider, string name, string email)
        {
            //TODO: move all of this logic to UserManager
            string newSessionToken = Guid.NewGuid().ToString();

            var dataModel = new OCMEntities();
            var userDetails = dataModel.Users.FirstOrDefault(u => u.Identifier.ToLower() == userIdentifier.ToLower() && u.IdentityProvider.ToLower() == loginProvider.ToLower());
            if (userDetails == null)
            {
                //create new user details
                userDetails = new Core.Data.User();
                userDetails.IdentityProvider = loginProvider;
                userDetails.Identifier = userIdentifier;
                if (String.IsNullOrEmpty(name) && loginProvider.ToLower() == "twitter") name = userIdentifier;
                if (String.IsNullOrEmpty(name) && email != null) name = email.Substring(0, email.IndexOf("@"));

                userDetails.Username = name;
                userDetails.EmailAddress = email;
                userDetails.DateCreated = DateTime.UtcNow;
                userDetails.DateLastLogin = DateTime.UtcNow;
                userDetails.IsProfilePublic = true;

                //only update session token if new (also done on logout)
                if (String.IsNullOrEmpty(userDetails.CurrentSessionToken)) userDetails.CurrentSessionToken = newSessionToken;

                dataModel.Users.Add(userDetails);
            }
            else
            {
                //update date last logged in and refresh users details if more information provided
                userDetails.DateLastLogin = DateTime.UtcNow;

                if (userDetails.Username == userDetails.Identifier && !String.IsNullOrEmpty(name)) userDetails.Username = name;
                if (String.IsNullOrEmpty(userDetails.EmailAddress) && !String.IsNullOrEmpty(email)) userDetails.EmailAddress = email;

                //only update session token if new (also done on logout)
                if (String.IsNullOrEmpty(userDetails.CurrentSessionToken)) userDetails.CurrentSessionToken = newSessionToken;
            }

            //get whichever session token we used
            //newSessionToken = userDetails.CurrentSessionToken;

            //store updates to user
            dataModel.SaveChanges();

            PerformCoreLogin(OCM.API.Common.Model.Extensions.User.FromDataModel(userDetails));

            if (!String.IsNullOrEmpty((string)Session["_redirectURL"]))
            {
                string returnURL = Session["_redirectURL"].ToString();
                return Redirect(returnURL);
            }
            else
            {
                //nowhere specified to redirect to, redirect to home page
                return RedirectToAction("Index", "Home");
            }
        }
Esempio n. 4
0
        /// <summary>
        /// used to replace a POI from an external source with a new OCM provided POI, updated POI must still be saved after to store association
        /// </summary>
        /// <param name="oldPOI"></param>
        /// <param name="updatedPOI"></param>
        public int SupersedePOI(OCMEntities dataModel, Model.ChargePoint oldPOI, Model.ChargePoint updatedPOI)
        {
            //When applying an edit to imported or externally provided data:
            //Save old item with new POI ID, Submission Status: Delisted - Superseded By Edit
            //Save edit over old POI ID, with Contributor set to OCM, Parent POI ID set to new (old) POI ID
            //This means that comments/photos/metadata etc for the old POI are preserved against the new POI

            //zero existing ids we want to move to superseded poi (otherwise existing items will be updated)
            oldPOI.ID = 0;
            oldPOI.UUID = null;
            if (oldPOI.AddressInfo != null) oldPOI.AddressInfo.ID = 0;
            if (oldPOI.Connections != null)
            {
                foreach (var connection in oldPOI.Connections)
                {
                    connection.ID = 0;
                }
            }
            oldPOI.SubmissionStatus = null;
            oldPOI.SubmissionStatusTypeID = (int)StandardSubmissionStatusTypes.Delisted_SupersededByUpdate;

            var supersededPOIData = this.PopulateChargePoint_SimpleToData(oldPOI, dataModel);
            supersededPOIData.DateLastStatusUpdate = DateTime.UtcNow;
            dataModel.ChargePoints.Add(supersededPOIData);
            dataModel.SaveChanges();

            //associate updated poi with older parent poi, set OCM as data provider
            updatedPOI.ParentChargePointID = supersededPOIData.ID;
            updatedPOI.DataProvider = null;
            updatedPOI.DataProvidersReference = null;
            updatedPOI.DataProviderID = (int)StandardDataProviders.OpenChargeMapContrib;

            //return new ID for the archived version of the POI
            return supersededPOIData.ID;
        }