public static long Intention(VM_Intention intention)
                {
                    long rezult = 0;

                    using (var exodusDB = new exodusEntities())
                    {
                        var Result = new ObjectParameter("Result", 0);

                        exodusDB.stp_Intention_Update(
                            obligationTypeID: (int)intention.ObligationType.ObligationTypeID,
                            obligationKindID: (long)intention.ObligationKind.ObligationKindID,
                            periodID: (int)intention.Period,
                            intentionTermID: (int)intention.IntentionTerm,
                            issuerUserID: intention.IntentionIssuer.UserID,
                            holderUserID: intention.IntentionHolder.UserID,
                            tagID: intention.IntentionTag.TagID,
                            applicationID: intention.IntentionApplication.ApplicationID,
                            intentionAmount: intention.IntentionAmount,
                            currencyID: (int)intention.CurrencyID,
                            intentionDurationMonths: intention.IntentionDurationMonths,
                            intentionStartDate: intention.IntentionStartDate,
                            intentionEndDate: intention.IntentionEndDate,
                            intentionIsActive: intention.IntentionIsActive,
                            intentionID: intention.IntentionID,
                            result: Result,
                            dayOfWeek: intention.IntentionDayOfWeek,
                            dayOfMonth: intention.IntentionDayOfMonth,
                            intentionMemo: intention.IntentionMemo
                            );

                        rezult = Convert.ToInt64(Result.Value);
                    }

                    return(rezult);
                }
                private static VM_Intention GetIntentionFromDB <T>(T intention)
                {
                    stp_Intention_ByID_Result rez = AutoMapper.Mapper.Map <stp_Intention_ByID_Result>(intention);

                    VM_Intention vmIntention = new VM_Intention()
                    {
                        CurrencyID           = (En_Currency)rez.CurrencyID,
                        IntentionAmount      = rez.IntentionAmount,
                        IntentionApplication = new VM_Application()
                        {
                            ApplicationID          = rez.ApplicationID,
                            ApplicationDescription = rez.ApplicationDescription,
                            ApplicationIsActive    = rez.ApplicationIsActive,
                            ApplicationNameEng     = rez.ApplicationNameEng,
                            ApplicationNameRus     = rez.ApplicationNameRus
                        },
                        IntentionDurationMonths = rez.IntentionDurationMonths,
                        IntentionEndDate        = rez.IntentionEndDate,
                        IntentionHolder         = new VM_User()
                        {
                            UserID        = rez.HolderUserID,
                            UserFirstName = rez.HolderUserFirstName,
                            UserLastName  = rez.HolderUserLastName,
                            Avatar        = Global.Cache.GetAvatar(rez.HolderUserID)
                        },
                        IntentionID       = rez.IntentionID,
                        IntentionIsActive = rez.IntentionIsActive,
                        IntentionIssuer   = new VM_User()
                        {
                            UserID        = rez.IssuerUserID,
                            UserFirstName = rez.IssuerUserFirstName,
                            UserLastName  = rez.IssuerUserLastName,
                            Avatar        = Global.Cache.GetAvatar(rez.IssuerUserID)
                        },
                        IntentionStartDate = rez.IntentionStartDate,
                        IntentionTag       = new VM_Tag()
                        {
                            TagID       = rez.TagID.HasValue ? rez.TagID.Value : 0,
                            NameEng     = rez.TagNameEng,
                            NameRus     = rez.TagNameRus,
                            Description = rez.TagDescription
                        },
                        IntentionTerm  = (EN_IntentionTerm)rez.IntentionTermID,
                        ObligationKind = new VM_ObligationKind()
                        {
                            ObligationComment = rez.ObligationComment,
                            ObligationKindID  = (EN_ObligationKind)rez.ObligationKindID,
                            ObligationNameEng = rez.ObligationNameEng,
                            ObligationNameRus = rez.ObligationNameRus
                        },
                        ObligationType = new VM_ObligationType()
                        {
                            ObligationTypeComment = rez.ObligationTypeComment,
                            ObligationTypeID      = (EN_ObligationType)rez.ObligationTypeID,
                            ObligationTypeNameEng = rez.ObligationTypeNameEng,
                            ObligationTypeNameRus = rez.ObligationTypeNameRus
                        },
                        Period = (EN_Period)rez.PeriodID,
                        IntentionDayOfMonth = rez.IntentionDayOfMonth.HasValue ? rez.IntentionDayOfMonth.Value : 0,
                        IntentionDayOfWeek  = rez.IntentionDayOfWeek.HasValue ? rez.IntentionDayOfWeek.Value : 0,
                        IntentionMemo       = rez.IntentionMemo
                    };

                    return(vmIntention);
                }
Exemple #3
0
        public ActionResult Join(VM_TagJoinDetails tagJoinDetails)
        {
            // User
            var user = _DL.User.Get.ByID(tagJoinDetails.UserID);

            if (user == null)
            {
                return(RedirectToAction("UserNotFound", "Errors"));
            }
            // Tag
            var tag = _DL.Tag.Get.ByID(tagJoinDetails.TagID);

            if (tag == null)
            {
                return(RedirectToAction("TagNotFound", "Errors"));
            }
            // If Exists
            if (_DL.Tag.Get.ByUserID(CurrentUser.UserID).Where(a => a.TagID == tagJoinDetails.TagID).Count() != 0 || user.UserID == CurrentUser.UserID)
            {
                return(RedirectToAction("TagCanNotAddYourSelf", "Errors",
                                        new
                {
                    backurl = this.Url.Action("OpenTag", "Desktop", new { TagID = tagJoinDetails.TagID })
                }));
            }
            else
            {
                //
                VM_Intention intention = new VM_Intention()
                {
                    CurrencyID      = tagJoinDetails.IntentionCurrencyID,
                    IntentionAmount = tagJoinDetails.IntentionAmount,
                    ObligationType  = new VM_ObligationType {
                        ObligationTypeID = EN_ObligationType.Money
                    },
                    ObligationKind       = _DL.Obligation.Get.KindDefault_ByAppID(tag.ApplicationID),
                    Period               = tagJoinDetails.Period,
                    IntentionTerm        = tagJoinDetails.IntentionTerm,
                    IntentionIssuer      = CurrentUser,
                    IntentionHolder      = user,
                    IntentionTag         = tag,
                    IntentionApplication = new VM_Application {
                        ApplicationID = tag.ApplicationID
                    },
                    IntentionDurationMonths = 0,
                    IntentionStartDate      = DateTime.Now,
                    IntentionEndDate        = tag.EndDate,
                    IntentionIsActive       = true,
                    IntentionDayOfMonth     = tag.DayOfMonth,
                    IntentionDayOfWeek      = tag.DayOfWeek,
                };
                //
                long rezIntention = _DL.Intention.Add.Intention(intention);
                long rezAdd       = _DL.Tag.Add.AddUserAsMember(tag.TagID, CurrentUser.UserID);
                //
                decimal totalSum = _DL.Intention.Get.Intention_Sum_ByTagID(tag.TagID);
                // If total amount bigger then tag amount
                if (totalSum >= tag.TotalAmount && tag.ApplicationType == EN_ApplicationType.Own_Initiative)
                {
                    Dictionary <string, string> dic = new Dictionary <string, string>();
                    EN_EventType type = EN_EventType.Own_Initiative_Tag_Reached_Target_Amount_Including_Intentions;
                    // Add Keys
                    dic.Add("TagID", tag.TagID.ToString());
                    // Create new event
                    new EventModel(dic, type);
                }
                //
                if (_DL.Events.Get.ByID(tagJoinDetails.EventID) != null)
                {
                    // Set Event Read
                    _DL.Events.Update.MarkETU_Processed(CurrentUser.UserID, tagJoinDetails.EventID);
                }
                //
                EventCreator.UserHasJoinedTagUponYourInvitation(tag.TagID, CurrentUser.UserID, tagJoinDetails.UserID, tag.ApplicationID);
                //
                return(RedirectToAction("Index", "Desktop", new { TagID = tag.TagID }));
            }
        }