Example #1
0
 //update a diary by normal user
 public int updateDiaryByUser(Guid Diary_id, string Diary_Subject, string Diary_Content)
 {
     using (DatabaseContext db = new DatabaseContext())
     {
         DiaryDetail diary = db.DiaryDetails.Find(Diary_id);
         diary.Diary_Subject = Diary_Subject;
         diary.Diary_Content = Diary_Content;
         try
         {
             db.Entry(diary).State = EntityState.Modified;
             db.SaveChanges();
             //successfully updated details
             return(1);
         }
         catch
         {
             //internal error occured while updating existing diary
             return(0);
         }
     }
 }
Example #2
0
 //update a diary by official user
 public int updateDiaryByOfficial(string email, Guid diary_Id, int setAcceptance)
 {
     using (DatabaseContext db = new DatabaseContext())
     {
         DiaryDetail diary = db.DiaryDetails.Find(diary_Id);
         diary.Diary_IsAccepted = setAcceptance;
         diary.Diary_ViewDate   = CurrentIndianTime();
         diary.Diary_AcceptedBy = getAccountId(email);
         try
         {
             db.Entry(diary).State = EntityState.Modified;
             db.SaveChanges();
             //successfully updated details
             return(1);
         }
         catch
         {
             //internal error occured while updating existing diary
             return(0);
         }
     }
 }
Example #3
0
        //Register a diary
        public int registerDiary(string email, string Diary_Subject, string Diary_Content)
        {
            if (!String.IsNullOrWhiteSpace(Diary_Subject) && !String.IsNullOrWhiteSpace(Diary_Content))
            {
                using (DatabaseContext db = new DatabaseContext())
                {
                    DiaryDetail diary = new DiaryDetail();

                    diary.Diary_Id          = CreateUniqueId();
                    diary.Account_Id        = getAccountId(email);
                    diary.Diary_Subject     = Diary_Subject;
                    diary.Diary_Content     = Diary_Content;
                    diary.Diary_SubmittedAt = CurrentIndianTime();
                    // 2 means pending
                    diary.Diary_IsAccepted = 2;
                    diary.Diary_ViewDate   = null;
                    diary.Diary_AcceptedBy = null;

                    try
                    {
                        db.DiaryDetails.Add(diary);
                        db.SaveChanges();
                        //Successfully created the diary
                        return(1);
                    }
                    catch
                    {
                        //Internal error occured while registering the diary.
                        return(2);
                    }
                }
            }
            else
            {
                //Mandetory fields are empty. Error occured.
                return(0);
            }
        }