Esempio n. 1
0
        public async Task <object> PostActivity(Activity activity)
        {
            dynamic cResponse = new ExpandoObject();

            try
            {
                if (!ModelState.IsValid)
                {
                    cResponse.Result      = "-1";
                    cResponse.Description = ModelState;
                    return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
                }

                activity.IsHidden     = false;
                activity.ActivityDate = DateTime.Now;
                db.Activity.Add(activity);
                await db.SaveChangesAsync();

                cResponse.Result      = "0";
                cResponse.Description = "Activity added to database";
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }
            catch
            {
                cResponse.Result      = "-1";
                cResponse.Description = "Exception, your request could not be executed";
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }
        }
Esempio n. 2
0
        public async Task <IHttpActionResult> PutComment(int id, Comment comment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != comment.CommentID)
            {
                return(BadRequest());
            }

            db.Entry(comment).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> PutDeviceType(int id, DeviceType deviceType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != deviceType.DeviceTypeID)
            {
                return(BadRequest());
            }

            db.Entry(deviceType).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DeviceTypeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> PutFeedbackCategory(int id, FeedbackCategory feedbackCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != feedbackCategory.CategoryID)
            {
                return(BadRequest());
            }

            db.Entry(feedbackCategory).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FeedbackCategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <object> PostStory(Story story)
        {
            dynamic cResponse = new ExpandoObject();

            try
            {
                if (!ModelState.IsValid)
                {
                    cResponse.Result      = "-1";
                    cResponse.Description = ModelState;
                    return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
                }

                story.CreatedDate = DateTime.Now;
                story.IsReported  = false;

                db.Story.Add(story);
                await db.SaveChangesAsync();

                cResponse.Result      = "0";
                cResponse.Description = "Story Added";
                cResponse.Story       = story;
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }
            catch (Exception ex)
            {
                cResponse.Result      = "-1";
                cResponse.Description = "Your request could not executed";
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }
        }
Esempio n. 6
0
        public async Task <object> PostMoment(List <Moment> momentList)
        {
            dynamic cResponse = new ExpandoObject();

            try
            {
                if (!ModelState.IsValid)
                {
                    cResponse.Result      = "-1";
                    cResponse.Description = ModelState;
                    return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
                }

                foreach (Moment nextMoment in momentList)
                {
                    nextMoment.IsSafe     = true;
                    nextMoment.UploadDate = DateTime.Now;
                }

                db.Moment.AddRange(momentList);
                await db.SaveChangesAsync();

                cResponse.Result      = "0";
                cResponse.Description = "Moments Added";
                cResponse.Moments     = momentList;
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }
            catch (Exception ex)
            {
                cResponse.Result      = "-1";
                cResponse.Description = "Your request could not executed";
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }
        }
Esempio n. 7
0
        public async Task <object> PostMomentLike(MomentLike momentLike)
        {
            dynamic cResponse = new ExpandoObject();

            if (!ModelState.IsValid)
            {
                cResponse.Result      = "-1";
                cResponse.Description = ModelState;
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }

            int resultLike = await db.MomentLike.CountAsync(x => x.PersonID == momentLike.PersonID && x.MomentID == momentLike.MomentID);

            if (resultLike > 0)
            {
                cResponse.Result      = "-1";
                cResponse.Description = "Already Liked";
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }

            momentLike.LikeDate = DateTime.Now;

            db.MomentLike.Add(momentLike);
            await db.SaveChangesAsync();

            CountMoment dbCountMoment = await db.CountMoment.Where(x => x.MomentID == momentLike.MomentID).SingleOrDefaultAsync();

            if (dbCountMoment != null)
            {
                dbCountMoment.LastActivityDate = DateTime.Now;
                dbCountMoment.LikeCount        = dbCountMoment.LikeCount + 1;
                await db.SaveChangesAsync();
            }
            else
            {
                CountMoment newCountMoment = new CountMoment();
                newCountMoment.LastActivityDate = DateTime.Now;
                newCountMoment.MomentID         = momentLike.MomentID;
                newCountMoment.LikeCount        = 1;
                await db.SaveChangesAsync();
            }

            cResponse.Result      = "0";
            cResponse.Description = "Like added to database";
            return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
        }
Esempio n. 8
0
        public async Task <object> PostPerson(Person person)
        {
            dynamic cResponse = new ExpandoObject();

            if (!ModelState.IsValid)
            {
                cResponse.Result      = "-1";
                cResponse.Description = ModelState;
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }

            int resultEmail = await db.Person.CountAsync(x => x.Email == person.Email);

            if (resultEmail > 0)
            {
                cResponse.Result      = "-1";
                cResponse.Description = "Email is not available";
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }

            int resultUsername = await db.Person.CountAsync(x => x.Username == person.Username);

            if (resultUsername > 0)
            {
                cResponse.Result      = "-1";
                cResponse.Description = "Username is not available";
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }

            person.IsEmailAllowed = true;
            person.IsPrivate      = false;
            person.IsPushAllowed  = true;
            person.IsSuspended    = false;
            person.LastLoginDate  = DateTime.Now;
            person.PersonRoleID   = 1;
            person.RegisterDate   = DateTime.Now;
            person.GenderID       = 3;

            db.Person.Add(person);
            await db.SaveChangesAsync();

            string tokenResult = BasicHelper.TokenCreate(person.PersonID);

            if (tokenResult == "-1")
            {
                cResponse.Result  = "-1";
                cResponse.Message = "Token could not created";
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }

            cResponse.Result      = "0";
            cResponse.Token       = tokenResult;
            cResponse.Description = "Person added to database";
            cResponse.Person      = person;
            return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
        }
        public async Task <IHttpActionResult> PostTimeline(Timeline timeline)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Timeline.Add(timeline);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = timeline.TimelineID }, timeline));
        }
        public async Task <object> PostMomentLike(MomentLike like)
        {
            dynamic cResponse = new ExpandoObject();

            try
            {
                MomentLike mLike = await db.MomentLike.Where(x => x.MomentID == like.MomentID && x.PersonID == like.PersonID).SingleOrDefaultAsync();

                if (mLike != null)
                {
                    db.MomentLike.Remove(mLike);
                    await db.SaveChangesAsync();

                    CountMoment mMoment = await db.CountMoment.FindAsync(like.MomentID);

                    if (mMoment != null)
                    {
                        mMoment.LastActivityDate = DateTime.Now;
                        mMoment.LikeCount        = mMoment.LikeCount - 1;
                        await db.SaveChangesAsync();
                    }

                    cResponse.Result      = "0";
                    cResponse.Description = "you unliked";
                    return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
                }
                else
                {
                    cResponse.Result      = "0";
                    cResponse.Description = "you unliked";
                    return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
                }
            }
            catch (Exception ex)
            {
                cResponse.Result      = "0";
                cResponse.Description = "Exception, your request could not be executed";
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }
        }
Esempio n. 11
0
        public async Task <object> PostPerson(Person personLogin)
        {
            string email    = null;
            string username = null;

            if (personLogin.Username.IndexOf("@") == -1)
            {
                username = personLogin.Username;
            }
            else
            {
                email = personLogin.Username;
            }

            Person person;

            if (email != null)
            {
                person = await db.Person.Where(x => x.Email == email && x.Password == personLogin.Password).FirstOrDefaultAsync();
            }
            else
            {
                person = await db.Person.Where(x => x.Username == username && x.Password == personLogin.Password).FirstOrDefaultAsync();
            }

            dynamic cResponse = new ExpandoObject();

            if (person == null)
            {
                cResponse.Result  = "-1";
                cResponse.Message = "Person Not Found";
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }

            string tokenResult = BasicHelper.TokenCreate(person.PersonID);

            if (tokenResult == "-1")
            {
                cResponse.Result  = "-1";
                cResponse.Message = "Token could not created";
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }

            person.LastLoginDate = DateTime.Now;
            await db.SaveChangesAsync();

            cResponse.Result = "0";
            cResponse.Token  = tokenResult;
            cResponse.Person = person;
            return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
        }
Esempio n. 12
0
        public async Task <object> PostPersonFollowing(PersonFollowing personFollowing)
        {
            dynamic cResponse = new ExpandoObject();

            if (personFollowing.PersonID == personFollowing.SecondaryPersonID)
            {
                cResponse.Result      = "-1";
                cResponse.Description = "You cannot follow yourself";
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }

            try
            {
                if (!ModelState.IsValid)
                {
                    cResponse.Result      = "-1";
                    cResponse.Description = ModelState;
                    return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
                }

                personFollowing.DateRequest = DateTime.Now;
                personFollowing.IsAccepted  = false;

                db.PersonFollowing.Add(personFollowing);
                await db.SaveChangesAsync();

                cResponse.Result      = "0";
                cResponse.Description = "Person Following Added";
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }
            catch
            {
                cResponse.Result      = "-1";
                cResponse.Description = "Exception, your request could not be executed";
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }
        }
Esempio n. 13
0
        // PUT: odata/People(5)
        public async Task <IHttpActionResult> Put([FromODataUri] int key, Delta <Person> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Person person = await db.Person.FindAsync(key);

            if (person == null)
            {
                return(NotFound());
            }

            patch.Put(person);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PersonExists(key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Updated(person));
        }
        public async Task <object> PostFeedback(Feedback feedback)
        {
            dynamic cResponse = new ExpandoObject();

            if (!ModelState.IsValid)
            {
                cResponse.Result      = "-1";
                cResponse.Description = ModelState;
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }

            feedback.IsRead    = false;
            feedback.IsReplied = false;
            feedback.SentDate  = DateTime.Now;

            db.Feedback.Add(feedback);
            await db.SaveChangesAsync();

            cResponse.Result      = "0";
            cResponse.Description = "Object Added";
            return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
        }
        public async Task <object> PostForgotPassword(PersonForgotPassword personForgotPassowrd)
        {
            dynamic cResponse = new ExpandoObject();

            try
            {
                // code uret mail gonder
                // person tablosunda yeni code'u kaydet
                // sifreyi degistirince code'u sifirla

                string email    = "";
                string username = "";

                if (personForgotPassowrd.Username.IndexOf("@") == -1)
                {
                    username = personForgotPassowrd.Username;
                }
                else
                {
                    email = personForgotPassowrd.Username;
                }

                Person person;

                if (email != null)
                {
                    person = await db.Person.Where(x => x.Username == username).FirstOrDefaultAsync();
                }
                else if (email != null)
                {
                    person = await db.Person.Where(x => x.Email == email).FirstOrDefaultAsync();
                }
                else
                {
                    cResponse.Result     = "-1";
                    cResponse.Descripton = "Bad request";
                    return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
                }

                if (person != null)
                {
                    if (personForgotPassowrd.NewPassword == null)
                    {
                        Random r    = new Random();
                        int    code = r.Next(10000, 99999);

                        person.Code = code;
                        await db.SaveChangesAsync();

                        SendEmail(person.Email, person.FirstName + " " + person.LastName, code);

                        cResponse.Result     = "0";
                        cResponse.Descripton = "Email sent";
                        return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
                    }
                    else
                    {
                        if (person.Code == personForgotPassowrd.Code)
                        {
                            person.Code          = null;
                            person.Password      = personForgotPassowrd.NewPassword;
                            person.LastLoginDate = DateTime.Now;
                            await db.SaveChangesAsync();

                            cResponse.Result = "0";
                            cResponse.Person = person;
                            return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
                        }
                        else
                        {
                            cResponse.Result     = "-1";
                            cResponse.Descripton = "Code not matched";
                            return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
                        }
                    }
                }
                else
                {
                    cResponse.Result     = "-1";
                    cResponse.Descripton = "Email or Username not matched";
                    return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
                }
            }
            catch
            {
                cResponse.Result     = "-1";
                cResponse.Descripton = "Your request could not be executed";
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }
        }
Esempio n. 16
0
        public async Task <object> PostDevice(DeviceNameModel device)
        {
            dynamic cResponse = new ExpandoObject();

            try
            {
                if (!ModelState.IsValid)
                {
                    cResponse.Result      = "-1";
                    cResponse.Description = ModelState;
                    return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
                }

                // get DeviceType and create new if not exist
                DeviceType dbDeviceType = await db.DeviceType.Where(x => x.Name == device.DeviceTypeName).SingleOrDefaultAsync();

                if (dbDeviceType == null)
                {
                    dbDeviceType      = new DeviceType();
                    dbDeviceType.Name = device.DeviceTypeName;

                    db.DeviceType.Add(dbDeviceType);
                    await db.SaveChangesAsync();
                }

                // get OsVersion and create new if not exist
                OsVersion dbOsVersion = await db.OsVersion.Where(x => x.Name == device.OsVersionName).SingleOrDefaultAsync();

                if (dbOsVersion == null)
                {
                    dbOsVersion      = new OsVersion();
                    dbOsVersion.Name = device.OsVersionName;

                    db.OsVersion.Add(dbOsVersion);
                    await db.SaveChangesAsync();
                }

                // get OsVersion and create new if not exist
                AppVersion dbAppVersion = await db.AppVersion.Where(x => x.Name == device.AppVersionName).SingleOrDefaultAsync();

                if (dbAppVersion == null)
                {
                    dbAppVersion      = new AppVersion();
                    dbAppVersion.Name = device.AppVersionName;

                    string[] dateTime = device.AppVersionDatePublish.Split('-');

                    int year  = Convert.ToInt16(dateTime[0]);
                    int month = Convert.ToInt16(dateTime[1]);
                    int day   = Convert.ToInt16(dateTime[2]);

                    DateTime dt = new DateTime(year, month, day);
                    dbAppVersion.DatePublish = dt;

                    db.AppVersion.Add(dbAppVersion);
                    await db.SaveChangesAsync();
                }

                Language dbLanguage = await db.Language.Where(x => x.Name == device.DeviceLanguageName).SingleOrDefaultAsync();

                if (dbLanguage == null)
                {
                    dbLanguage      = new Language();
                    dbLanguage.Name = device.DeviceLanguageName;

                    db.Language.Add(dbLanguage);
                }

                Device isFoundDevice = await db.Device.Where(x => x.DeviceToken == device.DeviceToken && x.IsActive == true && x.DeviceTypeID == dbDeviceType.DeviceTypeID).SingleOrDefaultAsync();

                if (isFoundDevice != null)
                {
                    bool isChanged = false;

                    if (isFoundDevice.OsVersionID != dbOsVersion.VersionID)
                    {
                        isChanged = true;
                    }

                    if (isFoundDevice.AppVersionID != dbAppVersion.VersionID)
                    {
                        isChanged = true;
                    }

                    if (isFoundDevice.DeviceOsID != device.DeviceOsID)
                    {
                        isChanged = true;
                    }

                    if (isFoundDevice.DeviceLanguageID != dbLanguage.LanguageID)
                    {
                        isChanged = true;
                    }

                    if (isFoundDevice.PersonID != device.PersonID)
                    {
                        isChanged = true;
                    }

                    if (isChanged)
                    {
                        isFoundDevice.IsActive = false;
                        await db.SaveChangesAsync();

                        await InsertNewDevice(device, dbDeviceType, dbOsVersion, dbAppVersion, dbLanguage);
                    }
                    else
                    {
                        isFoundDevice.DateLastLogin = DateTime.Now;
                        await db.SaveChangesAsync();
                    }

                    cResponse.Result      = "0";
                    cResponse.Description = "Device Updated";
                    return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
                }
                else
                {
                    await InsertNewDevice(device, dbDeviceType, dbOsVersion, dbAppVersion, dbLanguage);

                    cResponse.Result      = "0";
                    cResponse.Description = "Device added to database";
                    return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
                }
            }
            catch
            {
                cResponse.Result      = "-1";
                cResponse.Description = "Exception, your request could not be executed";
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }
        }