public ActionResult Edit(AdminRecipeViewModel recipeEditModel)
        {
            //if (ModelState.IsValid)
            //{

            //}
            #region Delete old RecipeItems
            var recipe = this.db.Recipes.All()
                         .Include(r => r.Categories)
                         .Include(r => r.RecipeItems)
                         .FirstOrDefault(r => r.RecipeID == recipeEditModel.RecipeID);
            var recipeItems = recipe.RecipeItems;
            foreach (var recipeItem in recipeItems.ToList())
            {
                foreach (var step in recipeItem.Steps.ToList())
                {
                    this.db.Steps.Delete(step);
                }
                foreach (var ingredient in recipeItem.RecipeItems_Ingredients.ToList())
                {
                    this.db.RecipeItems_Ingredients.Delete(ingredient);
                }
                this.db.RecipeItems.Delete(recipeItem);
            }

            db.SaveChanges();
            #endregion
            Recipe recipeForEdit = this.db.Recipes.GetById(recipeEditModel.RecipeID);
            recipeForEdit = ParseRecipeVMToRecipeModel_Update(recipeForEdit, recipeEditModel);

            this.db.Recipes.Update(recipeForEdit);
            int result = this.db.SaveChanges();



            if (result != 0)
            {
                return(RedirectToAction("Details", "Recipes", new { recipeID = recipeEditModel.RecipeID, title = recipeEditModel.Title.Replace(' ', '-'), area = "" }));
            }

            //ViewData["RecipeItemID"] = Request.Form["recipeItems.index"];
            recipeEditModel.ParentCategories   = db.Categories.AllParentCategories();
            recipeEditModel.ChildrenCategories = db.Categories.AllChildrenCategories();
            recipeEditModel.PrepTimeHours      = this.hours;
            recipeEditModel.PrepTimeMinutes    = this.minutes;
            recipeEditModel.CookTimeHours      = this.hours;
            recipeEditModel.CookTimeMinutes    = this.minutes;
            recipeEditModel.Serves             = this.servesArray;
            recipeEditModel.Rating             = this.rating;
            recipeEditModel.Sources            = this.db.Sources.All();
            recipeEditModel.Recommendation     = this.recommendationArray;
            return(View(recipeEditModel));
        }
示例#2
0
        public static bool AddFriendshipRequest(int fromUserUserId, string toUserUserName)
        {
            using (UowData db = new UowData())
            {
                User fromUser = UsersData.GetUserByUserId(fromUserUserId);
                User toUser = UsersData.GetUserByUserName(toUserUserName);

                if (fromUser == null || toUser == null)
                {
                    return false;
                }

                Friendship friendship = db.Friendships.All().Where(f => f.IsActive &&
                    (f.FromUserUserId == fromUser.UserId && f.ToUserUserId == toUser.UserId) ||
                    (f.FromUserUserId == toUser.UserId && f.ToUserUserId == fromUser.UserId)).FirstOrDefault();

                FriendshipRequest friendshipRequest = db.FriendshipRequests.All().Where(fr => fr.IsActive &&
                    (fr.FromUserUserId == fromUser.UserId && fr.ToUserUserId == toUser.UserId) ||
                    (fr.FromUserUserId == toUser.UserId && fr.ToUserUserId == fromUser.UserId)).FirstOrDefault();

                if (friendship == null && friendshipRequest == null)
                {
                    FriendshipRequest newFriendshipRequest = new FriendshipRequest(fromUser, toUser);

                    db.FriendshipRequests.Add(newFriendshipRequest);
                    db.SaveChanges();

                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
示例#3
0
        public ActionResult WriteComment(Comment comment)
        {
            if (comment != null)
            {
                var post = db.Posts.GetById(comment.Post.Id);
                if (post != null)
                {
                    comment.Post = post;
                    var user = db.Users.FindUser(User.Identity.GetUserId());
                    comment.User = user;
                    db.Comments.Add(comment);
                    db.SaveChanges();

                    return(PartialView("_SingleComment", comment));
                }
            }

            return(PartialView("_writeComment", comment));
        }
示例#4
0
        public static void AddNewRegisteredUser(RegisterModel registerModel)
        {
            using (UowData db = new UowData())
            {
                User newUser = new User(registerModel);

                db.Users.Add(newUser);
                db.SaveChanges();
            }
        }
示例#5
0
        public static void AddChatMessage(User user, string message)
        {
            using (UowData db = new UowData())
            {
                ChatMessage newChatMessage = new ChatMessage(user, message);

                db.ChatMessages.Add(newChatMessage);

                db.SaveChanges();
            }
        }
示例#6
0
        public ActionResult WriteComment(string content, int?postId, string id)
        {
            if (Request.IsAjaxRequest())
            {
                return(PartialView("_writeComment", postId));
            }

            var user = db.Users.FindUser(User.Identity.GetUserId());
            var pId  = int.Parse(id);
            var post = db.Posts.GetById(pId);

            var comment = new Comment
            {
                Content = content,
                User    = user,
                Post    = post
            };

            db.Comments.Add(comment);
            db.SaveChanges();

            return(RedirectToAction("PostAndComments", "Posts", new { postId = pId }));
        }
示例#7
0
 public static void Initialize(int facesCount)
 {
     using (UowData db = new UowData())
     {
         if (db.Faces.All().Count() == 0)
         {
             Face face;
             for (int i = 0; i < facesCount; i++)
             {
                 face = new Face();
                 db.Faces.Add(face);
             }
             db.SaveChanges();
         }
     }
 }
示例#8
0
        public ActionResult RecipeHitCounter(int recipeID)
        {
            IUowData db = new UowData();

            var oldRecipe = from rec in db.Recipes.All()
                            where rec.RecipeID == recipeID
                            select rec;

            Recipe newRecipe = oldRecipe.FirstOrDefault();

            newRecipe.NumberOfHits = newRecipe.NumberOfHits + 1;
            db.Recipes.Update(newRecipe);
            int result = db.SaveChanges();

            return(RedirectToAction("Details", recipeID));
        }
        public static void UpendToMsSQL ()
        {
            UowData sqlData = new UowData();
            MongoUow mongoData = new MongoUow();

            //var measure = new Measure { MeasureName = "Spas" };

            var collections = mongoData.Measurs.GetAll();

            
            using (sqlData)
            {
                foreach (var item in collections)
                {
                    string name = item.MeasureName;
                    int measureId = item.MeasureId;

                    Console.WriteLine("Name is : {0} Id is : {1}", name, measureId);


                    var sqlMeasure = new Measure
                    {
                        MeasureName = name
                    };

                    sqlData.Measures.Add(sqlMeasure);

                    sqlData.SaveChanges();


                }

            }


        }
示例#10
0
        public static bool ApproveFriendshipRequest(int friendshipRequestId)
        {
            using (UowData db = new UowData())
            {
                FriendshipRequest friendshipRequest = db.FriendshipRequests.GetById(friendshipRequestId);

                if (friendshipRequest != null && friendshipRequest.IsActive)
                {
                    bool addFriendshipSuccess = AddFriendship(friendshipRequest);

                    if (addFriendshipSuccess)
                    {
                        friendshipRequest.IsApproved = true;
                        friendshipRequest.Till = DateTime.Now;
                        friendshipRequest.IsActive = false;

                        db.SaveChanges();
                    }

                    return addFriendshipSuccess;
                }
                else
                {
                    return false;
                }
            }
        }
示例#11
0
        private void AddSaveDataSQL(DateTime date, double ProductId, double UnitPrice)
        {
            var data = new UowData();

            Sale exelSales = new Sale();
            exelSales.ProductId = (int)ProductId;
            exelSales.UnitPrice = (decimal)UnitPrice;
            exelSales.Date = date;

            data.Sales.Add(exelSales);
            data.SaveChanges();
        }
示例#12
0
        public static bool AddFriendship(FriendshipRequest friendshipRequst)
        {
            using (UowData db = new UowData())
            {
                IQueryable<Friendship> friendships =
                    from f in db.Friendships.All()
                    where ((f.FromUserUserId == friendshipRequst.FromUserUserId && f.ToUserUserId == friendshipRequst.ToUserUserId) ||
                        (f.ToUserUserId == friendshipRequst.FromUserUserId && f.FromUserUserId == friendshipRequst.ToUserUserId)) &&
                        f.IsActive
                    select f;

                if (friendships.Count() == 0)
                {
                    Friendship newFriendship = new Friendship(friendshipRequst);

                    db.Friendships.Add(newFriendship);

                    db.SaveChanges();

                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
示例#13
0
        public static bool  RentFace(int userId, int faceId, int state)
        {
            using (UowData db = new UowData())
            {
                IQueryable<FaceState> faceStates =
                    from f in db.FaceStates.All()
                    where f.Face.FaceId == faceId && f.IsActive && f.Owner.UserId == userId
                    select f;

                if (faceStates.Count() == 0)
                {
                    FaceState newFaceState = new FaceState(db.Faces.GetById(faceId), db.Users.GetById(userId));
                    newFaceState.IsActive = true;
                    newFaceState.State = state;

                    db.FaceStates.Add(newFaceState);

                    db.SaveChanges();

                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
示例#14
0
        public static bool UpdateFaceState(int userId, int faceId, int type, string purpose)
        {
            using (UowData db = new UowData())
            {
                FaceState faceState = db.FaceStates.All().Where(f => f.FaceId == faceId
                    && f.IsActive && f.OwnerUserId == userId).FirstOrDefault();

                if (faceState != null)
                {
                    FaceState newFaceState = new FaceState(faceState);
                    newFaceState.Type = type;
                    newFaceState.Purpose = purpose;

                    faceState.IsActive = false;
                    faceState.LeaveDateTime = DateTime.Now;

                    db.FaceStates.Add(newFaceState);

                    db.SaveChanges();

                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
示例#15
0
        public static bool LeaveFace(int userId, int faceId)
        {
            using (UowData db = new UowData())
            {
                IQueryable<FaceState> faceStates =
                    from f in db.FaceStates.All()
                    where f.FaceId == faceId && f.IsActive && f.Owner.UserId == userId
                    select f;

                if (faceStates.Count() > 0)
                {
                    foreach (var faceState in faceStates)
                    {
                        faceState.LeaveDateTime = DateTime.Now;
                        faceState.IsActive = false;
                    }

                    db.SaveChanges();

                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
示例#16
0
        public static bool BreakFriendship(int friendshipId, int userId)
        {
            using (UowData db = new UowData())
            {
                Friendship friendship = db.Friendships.GetById(friendshipId);
                User user = db.Users.GetById(userId);

                if (friendship != null && user != null && friendship.IsActive)
                {
                    friendship.Till = DateTime.Now;
                    friendship.BrokenFromUserId = user.UserId;
                    friendship.BrokenFromUserUserName = user.UserName;
                    friendship.IsActive = false;

                    db.SaveChanges();

                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
示例#17
0
        public static bool CancelFriendshipRequest(int friendshipRequestId, int userId)
        {
            using (UowData db = new UowData())
            {
                FriendshipRequest friendshipRequest = db.FriendshipRequests.GetById(friendshipRequestId);
                User user = db.Users.GetById(userId);

                if (friendshipRequest != null && user != null && friendshipRequest.IsActive &&
                    (friendshipRequest.FromUserUserId == user.UserId || friendshipRequest.ToUserUserId == user.UserId))
                {
                    friendshipRequest.Till = DateTime.Now;
                    friendshipRequest.IsActive = false;
                    friendshipRequest.CanceledFromUserUserId = user.UserId;
                    friendshipRequest.CanceledFromUserUserName = user.UserName;

                    db.SaveChanges();

                    return true;
                }
                else
                {
                    return false;
                }
            }
        }