public async Task <ActionResult> AllReceiver()
        {
            Guid            business_working = Guid.Parse(Session["BusinessWorking"].ToString());
            List <StockOut> stockOuts        = await applicationDbContext.StockOuts.Include("Product").Include("Product.Category").Where(x => x.Receiver_Id == null).ToListAsync();

            foreach (var stockOut in stockOuts)
            {
                stockOut.Receiver_Id = User.Identity.GetUserId();

                applicationDbContext.Entry(stockOut).State = System.Data.Entity.EntityState.Modified;

                BusinessUser businessUser = await applicationDbContext.BusinessUsers.FirstOrDefaultAsync(x => x.User_Id == stockOut.Receiver_Id && x.Business_Id == business_working);

                if (stockOut.Product.Category.ActionOut == ActionConstants.Sum)
                {
                    businessUser.Cash += stockOut.SalePrice * stockOut.Quantity;
                }
                else if (stockOut.Product.Category.ActionOut == ActionConstants.Rest)
                {
                    businessUser.Cash -= stockOut.SalePrice * stockOut.Quantity;
                }

                applicationDbContext.Entry(businessUser).State = System.Data.Entity.EntityState.Modified;

                await ActivityPublisher.Publish(User.Identity.GetUserId(), ActivityTypeConstants.Stock_Out_Receive, stockOut.Id, stockOut.Product.Name, business_working);
            }
            await applicationDbContext.SaveChangesAsync();

            return(Json(true));
        }
Esempio n. 2
0
        private void NotifyNewComment(FeedComment comment, Feed feed)
        {
            ActivityPublisher.AddFeedComment(comment, feed, SecurityContext.CurrentAccount.ID);
            var feedType = feed.FeedType == FeedType.Poll ? "poll" : "feed";

            var initatorInterceptor = new InitiatorInterceptor(new DirectRecipient(comment.Creator, ""));

            try
            {
                NewsNotifyClient.NotifyClient.AddInterceptor(initatorInterceptor);
                NewsNotifyClient.NotifyClient.SendNoticeAsync(
                    NewsConst.NewComment, feed.Id.ToString(),
                    null,
                    new TagValue(NewsConst.TagFEED_TYPE, feedType),
                    //new TagValue(NewsConst.TagAnswers, feed.Variants.ConvertAll<string>(v => v.Name)),
                    new TagValue(NewsConst.TagCaption, feed.Caption),
                    new TagValue("CommentBody", HtmlUtility.GetFull(comment.Comment, ASC.Web.Community.Product.CommunityProduct.ID)),
                    new TagValue(NewsConst.TagDate, comment.Date.ToShortString()),
                    new TagValue(NewsConst.TagURL, CommonLinkUtility.GetFullAbsolutePath("~/products/community/modules/news/?docid=" + feed.Id)),
                    new TagValue("CommentURL", CommonLinkUtility.GetFullAbsolutePath("~/products/community/modules/news/?docid=" + feed.Id + "#" + comment.Id.ToString())),
                    new TagValue(NewsConst.TagUserName, DisplayUserSettings.GetFullUserName(SecurityContext.CurrentAccount.ID)),
                    new TagValue(NewsConst.TagUserUrl, CommonLinkUtility.GetFullAbsolutePath(CommonLinkUtility.GetUserProfile(SecurityContext.CurrentAccount.ID, ASC.Web.Community.Product.CommunityProduct.ID))),
                    GetReplyToTag(feed, comment)
                    );
            }
            finally
            {
                NewsNotifyClient.NotifyClient.RemoveInterceptor(initatorInterceptor.Name);
            }
        }
Esempio n. 3
0
        public AjaxResponse Remove(string id)
        {
            try
            {
                CommunitySecurity.DemandPermissions(NewsConst.Action_Edit);
                AjaxResponse resp = new AjaxResponse();
                resp.rs1 = "0";
                if (!string.IsNullOrEmpty(id))
                {
                    var feedId  = Convert.ToInt64(id);
                    var storage = FeedStorageFactory.Create();

                    foreach (var comment in storage.GetFeedComments(feedId))
                    {
                        CommonControlsConfigurer.FCKUploadsRemoveForItem("news_comments", comment.Id.ToString());
                    }

                    ActivityPublisher.DeletePost(storage.GetFeed(Convert.ToInt64(id)), SecurityContext.CurrentAccount.ID);

                    storage.RemoveFeed(feedId);
                    CommonControlsConfigurer.FCKUploadsRemoveForItem("news", id);

                    resp.rs1 = id;
                    resp.rs2 = NewsResource.FeedDeleted;
                }
                return(resp);
            }
            catch (Exception err)
            {
                return(new AjaxResponse {
                    rs1 = "1", rs2 = err.Message,
                });
            }
        }
Esempio n. 4
0
        public async Task <ActionResult> Create(ProductModel model)
        {
            Guid business_working = Guid.Parse(Session["BusinessWorking"].ToString());

            if (ModelState.IsValid)
            {
                Product product = new Product()
                {
                    Id           = Guid.NewGuid(),
                    Name         = model.Product,
                    Category_Id  = Guid.Parse(model.Category),
                    Description  = "",
                    Stock        = model.Stock,
                    User_Id      = User.Identity.GetUserId(),
                    CurrentPrice = decimal.Parse(model.CurrentPrice.Replace(".", ",")),
                    LastUpdated  = DateTime.Now,
                    NoCountOut   = model.NoCountOut,
                    Business_Id  = business_working,
                    SalePrice    = decimal.Parse(model.SalePrice.Replace(".", ",")),
                    isAccesory   = model.isAccesory
                };

                applicationDbContext.Products.Add(product);

                await applicationDbContext.SaveChangesAsync();

                await ActivityPublisher.Publish(User.Identity.GetUserId(), ActivityTypeConstants.Stock_Create, product.Id, model.Product, business_working);

                return(RedirectToAction("Index"));
            }

            ViewBag.Categories = await applicationDbContext.Categories.Where(x => x.Business_Id == business_working).OrderBy(x => x.Name).ToListAsync();

            return(View(model));
        }
Esempio n. 5
0
        public async Task <ActionResult> Edit(string id, ProductModel model)
        {
            Guid business_working = Guid.Parse(Session["BusinessWorking"].ToString());

            if (ModelState.IsValid)
            {
                Guid prod_id = Guid.Parse(id);

                Product product = await applicationDbContext.Products.FirstOrDefaultAsync(x => x.Id == prod_id);

                product.Name         = model.Product;
                product.Category_Id  = Guid.Parse(model.Category);
                product.Stock        = model.Stock;
                product.CurrentPrice = decimal.Parse(model.CurrentPrice.Replace(".", ","));
                product.SalePrice    = decimal.Parse(model.SalePrice.Replace(".", ","));
                product.LastUpdated  = DateTime.Now;
                product.NoCountOut   = model.NoCountOut;
                product.isAccesory   = model.isAccesory;

                applicationDbContext.Entry(product).State = System.Data.Entity.EntityState.Modified;

                await applicationDbContext.SaveChangesAsync();

                await ActivityPublisher.Publish(User.Identity.GetUserId(), ActivityTypeConstants.Stock_Edit, product.Id, model.Product, business_working);

                return(RedirectToAction("Index"));
            }
            ViewBag.Categories = await applicationDbContext.Categories.Where(x => x.Business_Id == business_working).OrderBy(x => x.Name).ToListAsync();

            return(View(model));
        }
Esempio n. 6
0
        public static bool VoteForPoll(List <long> userAnswersIDs, IFeedStorage storage, long pollId, out string errorMessage)
        {
            errorMessage = string.Empty;
            storage.PollVote(SecurityContext.CurrentAccount.ID.ToString(), userAnswersIDs);
            var pollFeed = storage.GetFeed(pollId);

            if (pollFeed == null)
            {
                errorMessage = Resources.NewsResource.ErrorAccessDenied;
                return(false);
            }
            ActivityPublisher.Voted(pollFeed, SecurityContext.CurrentAccount.ID);
            return(true);
        }
        public async Task <ActionResult> Delete(string id)
        {
            Guid out_id           = Guid.Parse(id);
            Guid business_working = Guid.Parse(Session["BusinessWorking"].ToString());

            StockOut stockOut = await applicationDbContext.StockOuts.Include("Product").FirstOrDefaultAsync(x => x.Id == out_id);

            if (stockOut != null)
            {
                if (stockOut.Receiver_Id != null)
                {
                    if (!stockOut.Product.NoCountOut)
                    {
                        BusinessUser businessUser = await applicationDbContext.BusinessUsers.FirstOrDefaultAsync(x => x.User_Id == stockOut.Receiver_Id && x.Business_Id == business_working);

                        /*Operacion inversa para revertir la situación*/
                        if (stockOut.Product.Category.ActionOut == ActionConstants.Sum)
                        {
                            businessUser.Cash -= stockOut.SalePrice * stockOut.Quantity;
                        }
                        else if (stockOut.Product.Category.ActionOut == ActionConstants.Rest)
                        {
                            businessUser.Cash += stockOut.SalePrice * stockOut.Quantity;
                        }

                        applicationDbContext.Entry(businessUser).State = System.Data.Entity.EntityState.Modified;
                    }
                }

                stockOut.Product.Stock      += stockOut.Quantity;
                stockOut.Product.LastUpdated = DateTime.Now;

                applicationDbContext.Entry(stockOut.Product).State = System.Data.Entity.EntityState.Modified;
                applicationDbContext.Entry(stockOut).State         = System.Data.Entity.EntityState.Deleted;
                await ActivityPublisher.Publish(User.Identity.GetUserId(), ActivityTypeConstants.Stock_Out_Remove, stockOut.Id, stockOut.Product.Name, business_working);

                await applicationDbContext.SaveChangesAsync();
            }

            ViewBag.Msg = "La salida ha sido eliminada correctamente";

            return(RedirectToAction("Index"));
        }
Esempio n. 8
0
        public AjaxResponse Remove(string id)
        {
            AjaxResponse resp = new AjaxResponse();

            resp.rs1 = "0";
            if (!string.IsNullOrEmpty(id))
            {
                CommunitySecurity.DemandPermissions(NewsConst.Action_Edit);

                var storage = FeedStorageFactory.Create();
                ActivityPublisher.DeletePost(storage.GetFeed(Convert.ToInt64(id)), SecurityContext.CurrentAccount.ID);
                storage.RemoveFeed(Convert.ToInt64(id, CultureInfo.CurrentCulture));

                CommonControlsConfigurer.FCKUploadsRemoveForItem("news", id);

                resp.rs1 = id;
                resp.rs2 = NewsResource.FeedDeleted;
            }
            return(resp);
        }
Esempio n. 9
0
 public void UpdateFeedComment(FeedComment comment)
 {
     SaveFeedComment(comment);
     ActivityPublisher.EditFeedComment(GetFeed(comment.FeedId), SecurityContext.CurrentAccount.ID);
 }
Esempio n. 10
0
        private void NotifyFeed(Feed feed, bool isEdit, FeedType type)
        {
            if (isEdit)
            {
                ActivityPublisher.EditPost(feed, SecurityContext.CurrentAccount.ID);
            }
            else
            {
                var initatorInterceptor = new InitiatorInterceptor(new DirectRecipient(feed.Creator, ""));
                try
                {
                    NewsNotifyClient.NotifyClient.AddInterceptor(initatorInterceptor);
                    var replyToTag = GetReplyToTag(feed, null);
                    if (type == FeedType.Poll && feed is FeedPoll)
                    {
                        NewsNotifyClient.NotifyClient.SendNoticeAsync(
                            NewsConst.NewFeed, null, null,
                            new TagValue(NewsConst.TagFEED_TYPE, "poll"),
                            new TagValue(NewsConst.TagAnswers, ((FeedPoll)feed).Variants.ConvertAll <string>(v => v.Name)),
                            new TagValue(NewsConst.TagCaption, feed.Caption),
                            new TagValue(NewsConst.TagText, HtmlUtility.GetFull(feed.Text, ASC.Web.Community.Product.CommunityProduct.ID)),
                            new TagValue(NewsConst.TagDate, feed.Date.ToShortString()),
                            new TagValue(NewsConst.TagURL, CommonLinkUtility.GetFullAbsolutePath("~/products/community/modules/news/?docid=" + feed.Id)),
                            new TagValue(NewsConst.TagUserName, DisplayUserSettings.GetFullUserName(SecurityContext.CurrentAccount.ID)),
                            new TagValue(NewsConst.TagUserUrl, CommonLinkUtility.GetFullAbsolutePath(CommonLinkUtility.GetUserProfile(SecurityContext.CurrentAccount.ID, ASC.Web.Community.Product.CommunityProduct.ID))),
                            replyToTag
                            );
                    }
                    else
                    {
                        NewsNotifyClient.NotifyClient.SendNoticeAsync(
                            NewsConst.NewFeed, null, null,
                            new TagValue(NewsConst.TagFEED_TYPE, "feed"),
                            new TagValue(NewsConst.TagCaption, feed.Caption),
                            new TagValue(NewsConst.TagText,
                                         HtmlUtility.GetFull(feed.Text, ASC.Web.Community.Product.CommunityProduct.ID)),
                            new TagValue(NewsConst.TagDate, feed.Date.ToShortString()),
                            new TagValue(NewsConst.TagURL,
                                         CommonLinkUtility.GetFullAbsolutePath(
                                             "~/products/community/modules/news/?docid=" + feed.Id)),
                            new TagValue(NewsConst.TagUserName,
                                         DisplayUserSettings.GetFullUserName(SecurityContext.CurrentAccount.ID)),
                            new TagValue(NewsConst.TagUserUrl,
                                         CommonLinkUtility.GetFullAbsolutePath(
                                             CommonLinkUtility.GetUserProfile(SecurityContext.CurrentAccount.ID,
                                                                              ASC.Web.Community.Product.CommunityProduct.ID))),
                            replyToTag
                            );
                    }
                    ActivityPublisher.AddFeed(feed);

                    // subscribe to new comments
                    var subsciber = NewsNotifySource.Instance.GetSubscriptionProvider();
                    var me        = (IDirectRecipient)NewsNotifySource.Instance.GetRecipientsProvider().GetRecipient(SecurityContext.CurrentAccount.ID.ToString());
                    if (me != null && !subsciber.IsUnsubscribe(me, NewsConst.NewComment, feed.Id.ToString()))
                    {
                        subsciber.Subscribe(NewsConst.NewComment, feed.Id.ToString(), me);
                    }
                }
                finally
                {
                    NewsNotifyClient.NotifyClient.RemoveInterceptor(initatorInterceptor.Name);
                }
            }
        }
        public async Task <ActionResult> Create(StockOutModel model)
        {
            Guid business_working = Guid.Parse(Session["BusinessWorking"].ToString());

            if (ModelState.IsValid)
            {
                Guid productId = Guid.Parse(model.ProductName);

                Product product = await applicationDbContext.Products.Include("Category").FirstOrDefaultAsync(x => x.Id == productId);

                StockOut stockOut = new StockOut()
                {
                    Id          = Guid.NewGuid(),
                    Product_Id  = productId,
                    Date        = DateTime.Now,
                    Quantity    = model.Quantity,
                    SalePrice   = decimal.Parse(model.SalePrice.Replace(".", ",")),
                    User_Id     = User.Identity.GetUserId(),
                    Gain        = decimal.Parse(model.SalePrice.Replace(".", ",")) - product.CurrentPrice,
                    Description = model.Description
                };

                if (RoleManager.IsInRole(RoleManager.Editor) || RoleManager.IsInRole(RoleManager.Administrator))
                {
                    stockOut.Receiver_Id = User.Identity.GetUserId();

                    BusinessUser businessUser = await applicationDbContext.BusinessUsers.FirstOrDefaultAsync(x => x.User_Id == stockOut.Receiver_Id && x.Business_Id == business_working);

                    if (product.Category.ActionOut == ActionConstants.Sum)
                    {
                        businessUser.Cash += stockOut.SalePrice * stockOut.Quantity;
                    }
                    else if (product.Category.ActionOut == ActionConstants.Rest)
                    {
                        businessUser.Cash -= stockOut.SalePrice * stockOut.Quantity;
                    }

                    applicationDbContext.Entry(businessUser).State = System.Data.Entity.EntityState.Modified;
                }

                applicationDbContext.StockOuts.Add(stockOut);
                if (!product.NoCountOut)
                {
                    product.Stock      -= stockOut.Quantity;
                    product.LastUpdated = DateTime.Now;

                    applicationDbContext.Entry(product).State = System.Data.Entity.EntityState.Modified;
                }

                if (model.AccesoriesIds != null)
                {
                    foreach (var acc in model.AccesoriesIds)
                    {
                        Guid    accesory    = Guid.Parse(acc);
                        Product acc_product = await applicationDbContext.Products.Include("Category").FirstOrDefaultAsync(x => x.Id == accesory);

                        StockOut acc_stockOut = new StockOut()
                        {
                            Id          = Guid.NewGuid(),
                            Product_Id  = accesory,
                            Date        = DateTime.Now,
                            Quantity    = 1,
                            SalePrice   = 0,
                            User_Id     = User.Identity.GetUserId(),
                            Gain        = 0 - acc_product.CurrentPrice,
                            Description = $"Con producto {product.Name}"
                        };
                        applicationDbContext.StockOuts.Add(acc_stockOut);
                        if (!acc_product.NoCountOut)
                        {
                            acc_product.Stock      -= acc_stockOut.Quantity;
                            acc_product.LastUpdated = DateTime.Now;

                            applicationDbContext.Entry(acc_product).State = System.Data.Entity.EntityState.Modified;
                        }
                    }
                }

                await applicationDbContext.SaveChangesAsync();

                await ActivityPublisher.Publish(User.Identity.GetUserId(), ActivityTypeConstants.Stock_Out_Create, product.Id, product.Name, business_working);

                return(RedirectToAction("Index"));
            }

            ViewBag.Categories = await applicationDbContext.Categories.Where(x => x.Business_Id == business_working).OrderBy(x => x.Name).ToListAsync();

            return(View(model));
        }
Esempio n. 12
0
        public async Task <ActionResult> Create(StockInModel model)
        {
            Guid business_working = Guid.Parse(Session["BusinessWorking"].ToString());

            if (ModelState.IsValid)
            {
                Guid productId = Guid.Parse(model.ProductName);

                StockIn stockIn = new StockIn()
                {
                    Id          = Guid.NewGuid(),
                    Product_Id  = productId,
                    Date        = DateTime.Now,
                    Quantity    = model.Quantity,
                    ShopPrice   = decimal.Parse(model.ShopPrice.Replace(".", ",")),
                    User_Id     = User.Identity.GetUserId(),
                    Description = model.Description
                };

                if (Guid.Parse(model.Provider) != Guid.Empty)
                {
                    stockIn.Provider_Id = Guid.Parse(model.Provider);
                }

                applicationDbContext.StockIns.Add(stockIn);

                Product product = await applicationDbContext.Products.Include("Category").FirstOrDefaultAsync(x => x.Id == productId);

                product.CurrentPrice = ((product.CurrentPrice * product.Stock) + (stockIn.ShopPrice * stockIn.Quantity)) / (product.Stock + stockIn.Quantity);
                product.Stock       += stockIn.Quantity;
                product.LastUpdated  = DateTime.Now;

                if (RoleManager.IsInRole(RoleManager.Editor) || RoleManager.IsInRole(RoleManager.Administrator))
                {
                    BusinessUser businessUser = await applicationDbContext.BusinessUsers.FirstOrDefaultAsync(x => x.User_Id == stockIn.User_Id && x.Business_Id == business_working);

                    if (product.Category.ActionIn == ActionConstants.Sum)
                    {
                        businessUser.Cash += stockIn.ShopPrice * stockIn.Quantity;
                    }
                    else if (product.Category.ActionIn == ActionConstants.Rest)
                    {
                        businessUser.Cash -= stockIn.ShopPrice * stockIn.Quantity;
                    }

                    applicationDbContext.Entry(businessUser).State = System.Data.Entity.EntityState.Modified;
                }

                applicationDbContext.Entry(product).State = System.Data.Entity.EntityState.Modified;

                await applicationDbContext.SaveChangesAsync();

                await ActivityPublisher.Publish(User.Identity.GetUserId(), ActivityTypeConstants.Stock_In_Create, stockIn.Id, product.Name, business_working);

                return(RedirectToAction("Index"));
            }

            ViewBag.Categories = await applicationDbContext.Categories.Where(x => x.Business_Id == business_working).OrderBy(x => x.Name).ToListAsync();

            ViewBag.Providers = await applicationDbContext.Providers.Where(x => x.Business_Id == business_working).OrderBy(x => x.Name).ToListAsync();

            return(View(model));
        }