예제 #1
0
        public ActionResult Create(ActivityViewModel model)
        {
            try
            {
                Activity activity = new Activity()
                {
                    Budget = model.Budget, Date = DateTime.ParseExact(model.Date, "mm-dd-yyyy", System.Globalization.CultureInfo.InvariantCulture), Description = model.Description, OPDId = model.OPDId, Title = model.Title
                };

                var response = _actLogic.Create(activity);
                if (response.IsError == true)
                {
                    foreach (var item in response.ErrorCodes)
                    {
                        ModelState.AddModelError(string.Empty, item);
                    }
                    return(View(model));
                }

                return(RedirectToAction("View", "OPD", new { id = model.OPDId }));
            }
            catch
            {
                return(View());
            }
        }
        public async Task <int> Create(Deal model)
        {
            int Count = 0;

            using (var transaction = this.DbContext.Database.BeginTransaction())
            {
                try
                {
                    do
                    {
                        model.Code = CodeGenerator.Generate();
                    }while (this.DbSet.Any(d => d.Code.Equals(model.Code)));
                    DealLogic.Create(model);

                    Activity activity = new Activity()
                    {
                        DealId = model.Id, DealCode = model.Code, DealName = model.Name, Type = "ADD"
                    };

                    do
                    {
                        activity.Code = CodeGenerator.Generate();
                    }while (this.DbContext.DealTrackingActivities.Any(d => d.Code.Equals(activity.Code)));
                    ActivityLogic.Create(activity);

                    Count += await DbContext.SaveChangesAsync();

                    Count += await StageFacade.UpdateDealsOrderCreate(model.StageId, model.Id);
                }
                catch (DbUpdateConcurrencyException e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }

                transaction.Commit();
            }

            return(Count);
        }
        public async Task <int> Create(Activity model)
        {
            do
            {
                model.Code = CodeGenerator.Generate();
            }while (this.DbSet.Any(d => d.Code.Equals(model.Code)));

            if (model.Attachments.Count > 0)
            {
                foreach (ActivityAttachment attachment in model.Attachments)
                {
                    EntityExtension.FlagForCreate(attachment, IdentityService.Username, "deal-tracking-service");
                }
            }

            ActivityLogic.Create(model);
            return(await DbContext.SaveChangesAsync());
        }
예제 #4
0
        public void ActivityLogic()
        {
            Mock <IUnitOfWork>         uow       = new Mock <IUnitOfWork>();
            Mock <IActivityRepository> repo      = new Mock <IActivityRepository>();
            Mock <ITeamLogic>          teamLogic = new Mock <ITeamLogic>();

            ActivityLogic logic = new ActivityLogic(uow.Object, repo.Object, teamLogic.Object);

            var activity = new Activity();
            var sequence = new MockSequence();

            repo.InSequence(sequence).Setup(r => r.Create(activity));
            repo.InSequence(sequence).Setup(r => r.Update(activity));
            repo.InSequence(sequence).Setup(r => r.Get(activity.Id));
            repo.InSequence(sequence).Setup(r => r.Delete(activity.Id));
            logic.Create(activity);
            logic.Update(activity);
            logic.Get(activity.Id);
            logic.Delete(activity.Id);
        }