示例#1
0
 public HttpResponseMessage Update(MoneySource source)
 {
     return(Execute(session =>
     {
         var svc = new MoneySourceService();
         svc.Update(source);
         return Request.CreateResponse(HttpStatusCode.OK);
     }));
 }
示例#2
0
        public MoneySource Insert(MoneySource source)
        {
            return(Execute(session =>
            {
                var svc = new MoneySourceService();
                source.Owner = session.User;

                return svc.Insert(source);
            }));
        }
示例#3
0
        private void addMoneySourceButton_Click(object sender, EventArgs e)
        {
            // Получаем выбранный источник финансирования
            MoneySource selectedItem = moneySourceCBList.SelectedItem as MoneySource;

            // Создаём вкладку под выбранный источник
            CreateMoneySourceTab(new EstimateMoneyOnSourceTable
            {
                Source             = selectedItem,
                PrimarySumValues   = new decimal[kekvsList.Count, monthes.Length],
                SecondarySumValues = new decimal[kekvsList.Count, monthes.Length]
            });
        }
示例#4
0
        public MoneySource Insert(MoneySource moneySource)
        {
            var source = _adapter.Insert(moneySource);

            var userPermissionAdapter = new UserObjectPermissionDataAdapter();

            userPermissionAdapter.Insert(new UserObjectPermission
            {
                ObjectType = "MoneySource",
                ObjectId   = source.Id,
                Permission = PermissionEnum.Read | PermissionEnum.Create | PermissionEnum.Edit | PermissionEnum.Delete,
                User       = source.Owner
            });

            return(source);
        }
示例#5
0
        private static void ReverseSource(MoneySource source, PaymentRecord payment)
        {
            var amount = Convert.ToSingle(payment.Amount);

            if (payment.Type == "Order-Payment")
            {
                amount = -amount;
            }
            if (payment.Unit == "VND")
            {
                source.BalanceVND += amount;
            }
            else
            {
                source.BalanceUSD += amount;
            }
        }
示例#6
0
        internal static bool Update(BeneficiaryVM model)
        {
            dbContext db = new dbContext();

            var bene = model;

            using (var trans = db.Database.BeginTransaction())
            {
                try
                {
                    #region Beneficiary update
                    var beneficiaryInDB = db.Beneficiaries.Find(model.BeneficiaryID);
                    beneficiaryInDB.ScreeningDate                = model.ScreeningDate;
                    beneficiaryInDB.ProvinceBCP                  = model.ProvinceBCP;
                    beneficiaryInDB.BorderPoint                  = model.BorderPoint;
                    beneficiaryInDB.BeneficiaryType              = model.BeneficiaryType;
                    beneficiaryInDB.ReturnStatus                 = model.ReturnStatus;
                    beneficiaryInDB.OriginProvince               = model.OriginProvince;
                    beneficiaryInDB.OriginDistrict               = model.OriginDistrict;
                    beneficiaryInDB.OriginVillage                = model.OriginVillage;
                    beneficiaryInDB.ReturnProvince               = model.ReturnProvince;
                    beneficiaryInDB.ReturnDistrict               = model.ReturnDistrict;
                    beneficiaryInDB.ReturnVillage                = model.ReturnVillage;
                    beneficiaryInDB.LeavingReason1               = model.LeavingReason1;
                    beneficiaryInDB.LeavingReason1Other          = model.LeavingReason1Other;
                    beneficiaryInDB.LeavingReason2               = model.LeavingReason2;
                    beneficiaryInDB.LeavingReason2Other          = model.LeavingReason2Other;
                    beneficiaryInDB.LeavingReason3               = model.LeavingReason3;
                    beneficiaryInDB.LeavingReason3Other          = model.LeavingReason3Other;
                    beneficiaryInDB.OwnHouse                     = model.OwnHouse;
                    beneficiaryInDB.WhereWillLive                = model.WhereWillLive;
                    beneficiaryInDB.RentPayForAccom              = model.RentPayForAccom;
                    beneficiaryInDB.RentPayCurrency              = model.RentPayCurrency;
                    beneficiaryInDB.AllowForJob                  = model.AllowForJob;
                    beneficiaryInDB.CountryOfExile               = model.CountryOfExile;
                    beneficiaryInDB.CountryOfExilOther           = model.CountryOfExilOther;
                    beneficiaryInDB.BeforReturnProvince          = model.BeforReturnProvince;
                    beneficiaryInDB.BeforReturnDistrictID        = model.BeforReturnDistrictID;
                    beneficiaryInDB.BeforReturnRemarks           = model.BeforReturnRemarks;
                    beneficiaryInDB.FamilyMemStayedBehind        = model.FamilyMemStayedBehind;
                    beneficiaryInDB.FamilyMemStayedBehindNo      = model.FamilyMemStayedBehindNo;
                    beneficiaryInDB.LengthOfStayYears            = model.LengthOfStayYears;
                    beneficiaryInDB.LengthOfStayMonths           = model.LengthOfStayMonths;
                    beneficiaryInDB.LengthOfStayDays             = model.LengthOfStayDays;
                    beneficiaryInDB.WouldYouReturn               = model.WouldYouReturn;
                    beneficiaryInDB.HaveFamilyBenefited          = model.HaveFamilyBenefited;
                    beneficiaryInDB.TransportationDate           = model.TransportationDate;
                    beneficiaryInDB.TransportationInfo           = model.TransportationInfo;
                    beneficiaryInDB.TransportAccompaniedBy       = model.TransportAccompaniedBy;
                    beneficiaryInDB.TransportAccomByNo           = model.TransportAccomByNo;
                    beneficiaryInDB.TopNeed1                     = model.TopNeed1;
                    beneficiaryInDB.TopNeed1Other                = model.TopNeed1Other;
                    beneficiaryInDB.TopNeed2                     = model.TopNeed2;
                    beneficiaryInDB.TopNeed2Other                = model.TopNeed2Other;
                    beneficiaryInDB.TopNeed3                     = model.TopNeed3;
                    beneficiaryInDB.TopNeed3Other                = model.TopNeed3Other;
                    beneficiaryInDB.IntendToDo                   = model.IntendToDo;
                    beneficiaryInDB.IntendToReturnToHostReason   = model.IntendToReturnToHostReason;
                    beneficiaryInDB.ProfessionInHostCountry      = model.ProfessionInHostCountry;
                    beneficiaryInDB.ProfessionInHostCountryOther = model.ProfessionInHostCountryOther;
                    beneficiaryInDB.HoHCanReadWrite              = model.HoHCanReadWrite;
                    beneficiaryInDB.HoHEducationLevel            = model.HoHEducationLevel;
                    beneficiaryInDB.HoHEducationLevelOther       = model.HoHEducationLevelOther;
                    beneficiaryInDB.NumHHHaveTaskira             = model.NumHHHaveTaskira;
                    beneficiaryInDB.NumHHHavePassport            = model.NumHHHavePassport;
                    beneficiaryInDB.NumHHHaveDocOther            = model.NumHHHaveDocOther;
                    beneficiaryInDB.DoHaveSecureLivelihood       = model.DoHaveSecureLivelihood;
                    beneficiaryInDB.DidChildrenGoToSchoole       = model.DidChildrenGoToSchoole;
                    beneficiaryInDB.NumChildrenAttendedSchoole   = model.NumChildrenAttendedSchoole;
                    beneficiaryInDB.LastUpdatedBy                = UserInfo.ID;
                    beneficiaryInDB.LastUpdatedDate              = DateTime.Now;
                    db.SaveChanges();
                    #endregion

                    #region Update individuals
                    db.Individuals.RemoveRange(db.Individuals.Where(b => b.BeneficiaryID == beneficiaryInDB.BeneficiaryID));
                    db.SaveChanges();
                    foreach (var ind in model.Individuals)
                    {
                        var member = new Individual
                        {
                            BeneficiaryID     = beneficiaryInDB.BeneficiaryID,
                            Name              = ind.Name,
                            DrName            = ind.DrName,
                            FName             = ind.FName,
                            DrFName           = ind.DrFName,
                            GenderCode        = ind.GenderCode,
                            MaritalStatusCode = ind.MaritalStatusCode,
                            Age              = ind.Age,
                            IDTypeCode       = ind.IDTypeCode,
                            IDNo             = ind.IDNo,
                            RelationshipCode = ind.RelationshipCode,
                            ContactNumber    = ind.ContactNumber,
                        };
                        db.Individuals.Add(member);
                    }

                    #endregion

                    #region update PSN
                    db.PSNs.RemoveRange(db.PSNs.Where(b => b.BeneficiaryID == beneficiaryInDB.BeneficiaryID));
                    db.SaveChanges();
                    foreach (var psn in model.PSNs)
                    {
                        var psnObj = new PSN
                        {
                            BeneficiaryID = beneficiaryInDB.BeneficiaryID,
                            PSNCode       = psn.PSNCode,
                            PSNOther      = psn.PSNOther
                        };
                        db.PSNs.Add(psnObj);
                    }
                    #endregion

                    #region Upate Return Reason
                    db.ReturnReasons.RemoveRange(db.ReturnReasons.Where(b => b.BeneficiaryID == beneficiaryInDB.BeneficiaryID));
                    db.SaveChanges();
                    foreach (var rReason in model.ReturnReasons)
                    {
                        var rrObj = new ReturnReason
                        {
                            BeneficiaryID = beneficiaryInDB.BeneficiaryID,
                            ReasonCode    = rReason.ReasonCode,
                            Other         = rReason.Other
                        };
                        db.ReturnReasons.Add(rrObj);
                    }
                    #endregion

                    #region Update determination
                    db.Determinations.RemoveRange(db.Determinations.Where(b => b.BeneficiaryID == beneficiaryInDB.BeneficiaryID));
                    db.SaveChanges();
                    foreach (var d in model.Determinations)
                    {
                        var dObj = new Determination
                        {
                            BeneficiaryID     = beneficiaryInDB.BeneficiaryID,
                            DeterminationCode = d.DeterminationCode,
                            AnswerCode        = d.AnswerCode,
                            Other             = d.Other
                        };
                        db.Determinations.Add(dObj);
                    }
                    #endregion

                    #region Update Money Sources
                    db.MoneySources.RemoveRange(db.MoneySources.Where(b => b.BeneficiaryID == beneficiaryInDB.BeneficiaryID));
                    db.SaveChanges();
                    foreach (var m in model.MoneySources)
                    {
                        var moneySObj = new MoneySource
                        {
                            BeneficiaryID    = beneficiaryInDB.BeneficiaryID,
                            MoneySourceCode  = m.MoneySourceCode,
                            MoneySourceOther = m.MoneySourceOther
                        };
                        db.MoneySources.Add(moneySObj);
                    }
                    #endregion

                    #region Update Brought Items
                    db.BroughtItems.RemoveRange(db.BroughtItems.Where(b => b.BeneficiaryID == beneficiaryInDB.BeneficiaryID));
                    db.SaveChanges();
                    foreach (var bi in model.BroughtItems)
                    {
                        var biObj = new BroughtItem
                        {
                            BeneficiaryID = beneficiaryInDB.BeneficiaryID,
                            ItemCode      = bi.ItemCode,
                            ItemOther     = bi.ItemOther
                        };
                        db.BroughtItems.Add(biObj);
                    }
                    #endregion

                    #region Update post arrival needs
                    db.PostArrivalNeeds.RemoveRange(db.PostArrivalNeeds.Where(b => b.BeneficiaryID == beneficiaryInDB.BeneficiaryID));
                    db.SaveChanges();
                    foreach (var p in model.PostArrivalNeeds)
                    {
                        var panObj = new PostArrivalNeed
                        {
                            BeneficiaryID = beneficiaryInDB.BeneficiaryID,
                            NeedCode      = p.NeedCode,
                            Provided      = p.Provided,
                            ProvidedDate  = p.ProvidedDate,
                            Comment       = p.Comment
                        };
                        db.PostArrivalNeeds.Add(panObj);
                    }
                    #endregion

                    #region Update Assistance reveived from org
                    db.BenefitedFromOrgs.RemoveRange(db.BenefitedFromOrgs.Where(b => b.BeneficiaryID == beneficiaryInDB.BeneficiaryID));
                    db.SaveChanges();
                    if (model.HaveFamilyBenefited == true)
                    {
                        foreach (var a in model.BenefitedFromOrgs)
                        {
                            var assisOrgInfo = new BenefitedFromOrg
                            {
                                BeneficiaryID      = beneficiaryInDB.BeneficiaryID,
                                Date               = a.Date,
                                ProvinceCode       = a.ProvinceCode,
                                DistrictID         = a.DistrictID,
                                Village            = a.Village,
                                OrgCode            = a.OrgCode,
                                AssistanceProvided = a.AssistanceProvided
                            };
                            db.BenefitedFromOrgs.Add(assisOrgInfo);
                        }
                    }
                    #endregion

                    #region Update transportation
                    db.Transportations.RemoveRange(db.Transportations.Where(b => b.BeneficiaryID == beneficiaryInDB.BeneficiaryID));
                    db.SaveChanges();
                    foreach (var tran in model.Transportations)
                    {
                        var tranObj = new Transportation
                        {
                            BeneficiaryID = beneficiaryInDB.BeneficiaryID,
                            TypedCode     = tran.TypedCode,
                            Other         = tran.Other
                        };
                        db.Transportations.Add(tranObj);
                    }
                    #endregion

                    #region Update Need for livelihood and emplyment
                    db.LivelihoodEmpNeeds.RemoveRange(db.LivelihoodEmpNeeds.Where(b => b.BeneficiaryID == beneficiaryInDB.BeneficiaryID));
                    db.SaveChanges();
                    foreach (var li in model.LivelihoodEmpNeeds)
                    {
                        var liObj = new LivelihoodEmpNeed
                        {
                            BeneficiaryID = beneficiaryInDB.BeneficiaryID,
                            NeedCode      = li.NeedCode
                        };
                        db.LivelihoodEmpNeeds.Add(liObj);
                    }
                    #endregion

                    #region Update Need Tools
                    db.NeedTools.RemoveRange(db.NeedTools.Where(b => b.BeneficiaryID == beneficiaryInDB.BeneficiaryID));
                    db.SaveChanges();
                    foreach (var needTool in model.NeedTools)
                    {
                        var needToolObj = new NeedTool
                        {
                            BeneficiaryID = beneficiaryInDB.BeneficiaryID,
                            ToolCode      = needTool.ToolCode,
                            Other         = needTool.Other
                        };
                        db.NeedTools.Add(needToolObj);
                    }
                    #endregion

                    #region Update 3 main concerns
                    db.MainConcerns.RemoveRange(db.MainConcerns.Where(b => b.BeneficiaryID == beneficiaryInDB.BeneficiaryID));
                    db.SaveChanges();
                    foreach (var mConcern in model.MainConcerns)
                    {
                        var mcObj = new MainConcern
                        {
                            BeneficiaryID = beneficiaryInDB.BeneficiaryID,
                            ConcernCode   = mConcern.ConcernCode,
                            Other         = mConcern.Other
                        };
                        db.MainConcerns.Add(mcObj);
                    }
                    #endregion

                    #region Update host country schools
                    db.HostCountrySchools.RemoveRange(db.HostCountrySchools.Where(b => b.BeneficiaryID == beneficiaryInDB.BeneficiaryID));
                    db.SaveChanges();
                    foreach (var hc in model.HostCountrySchools)
                    {
                        var hcObj = new HostCountrySchool
                        {
                            BeneficiaryID  = beneficiaryInDB.BeneficiaryID,
                            SchoolTypeCode = hc.SchoolTypeCode
                        };
                        db.HostCountrySchools.Add(hcObj);
                    }
                    #endregion

                    db.SaveChanges();

                    trans.Commit();
                    return(true);
                }
                catch (Exception e)
                {
                    trans.Rollback();
                    return(false);
                }
            }
        }
示例#7
0
        public static bool Add(BeneficiaryVM model)
        {
            dbContext db = new dbContext();


            using (var trans = db.Database.BeginTransaction())
            {
                try
                {
                    var beneficiary = new Beneficiary
                    {
                        GUID                         = Guid.NewGuid(),
                        ScreeningDate                = model.ScreeningDate,
                        ProvinceBCP                  = model.ProvinceBCP,
                        BorderPoint                  = model.BorderPoint,
                        BeneficiaryType              = model.BeneficiaryType,
                        ReturnStatus                 = model.ReturnStatus,
                        OriginProvince               = model.OriginProvince,
                        OriginDistrict               = model.OriginDistrict,
                        OriginVillage                = model.OriginVillage,
                        ReturnProvince               = model.ReturnProvince,
                        ReturnDistrict               = model.ReturnDistrict,
                        ReturnVillage                = model.ReturnVillage,
                        LeavingReason1               = model.LeavingReason1,
                        LeavingReason1Other          = model.LeavingReason1Other,
                        LeavingReason2               = model.LeavingReason2,
                        LeavingReason2Other          = model.LeavingReason2Other,
                        LeavingReason3               = model.LeavingReason3,
                        LeavingReason3Other          = model.LeavingReason3Other,
                        OwnHouse                     = model.OwnHouse,
                        WhereWillLive                = model.WhereWillLive,
                        RentPayForAccom              = model.RentPayForAccom,
                        RentPayCurrency              = model.RentPayCurrency,
                        AllowForJob                  = model.AllowForJob,
                        CountryOfExile               = model.CountryOfExile,
                        CountryOfExilOther           = model.CountryOfExilOther,
                        BeforReturnProvince          = model.BeforReturnProvince,
                        BeforReturnDistrictID        = model.BeforReturnDistrictID,
                        BeforReturnRemarks           = model.BeforReturnRemarks,
                        FamilyMemStayedBehind        = model.FamilyMemStayedBehind,
                        FamilyMemStayedBehindNo      = model.FamilyMemStayedBehindNo,
                        LengthOfStayYears            = model.LengthOfStayYears,
                        LengthOfStayMonths           = model.LengthOfStayMonths,
                        LengthOfStayDays             = model.LengthOfStayDays,
                        WouldYouReturn               = model.WouldYouReturn,
                        HaveFamilyBenefited          = model.HaveFamilyBenefited,
                        TransportationDate           = model.TransportationDate,
                        TransportationInfo           = model.TransportationInfo,
                        TransportAccompaniedBy       = model.TransportAccompaniedBy,
                        TransportAccomByNo           = model.TransportAccomByNo,
                        TopNeed1                     = model.TopNeed1,
                        TopNeed1Other                = model.TopNeed1Other,
                        TopNeed2                     = model.TopNeed2,
                        TopNeed2Other                = model.TopNeed2Other,
                        TopNeed3                     = model.TopNeed3,
                        TopNeed3Other                = model.TopNeed3Other,
                        IntendToDo                   = model.IntendToDo,
                        IntendToReturnToHostReason   = model.IntendToReturnToHostReason,
                        ProfessionInHostCountry      = model.ProfessionInHostCountry,
                        ProfessionInHostCountryOther = model.ProfessionInHostCountryOther,
                        HoHCanReadWrite              = model.HoHCanReadWrite,
                        HoHEducationLevel            = model.HoHEducationLevel,
                        HoHEducationLevelOther       = model.HoHEducationLevelOther,
                        NumHHHaveTaskira             = model.NumHHHaveTaskira,
                        NumHHHavePassport            = model.NumHHHavePassport,
                        NumHHHaveDocOther            = model.NumHHHaveDocOther,
                        DoHaveSecureLivelihood       = model.DoHaveSecureLivelihood,
                        DidChildrenGoToSchoole       = model.DidChildrenGoToSchoole,
                        NumChildrenAttendedSchoole   = model.NumChildrenAttendedSchoole,
                        InsertedDate                 = DateTime.Now,
                        IsActive                     = true
                    };
                    db.Beneficiaries.Add(beneficiary);
                    db.SaveChanges();

                    foreach (var ind in model.Individuals)
                    {
                        var member = new Individual {
                            BeneficiaryID     = beneficiary.BeneficiaryID,
                            Name              = ind.Name,
                            DrName            = ind.DrName,
                            FName             = ind.FName,
                            DrFName           = ind.DrFName,
                            GenderCode        = ind.GenderCode,
                            MaritalStatusCode = ind.MaritalStatusCode,
                            Age              = ind.Age,
                            IDTypeCode       = ind.IDTypeCode,
                            IDNo             = ind.IDNo,
                            RelationshipCode = ind.RelationshipCode,
                            ContactNumber    = ind.ContactNumber
                        };
                        db.Individuals.Add(member);
                    }

                    foreach (var psn in model.PSNs)
                    {
                        var psnObj = new PSN {
                            BeneficiaryID = beneficiary.BeneficiaryID,
                            PSNCode       = psn.PSNCode,
                            PSNOther      = psn.PSNOther
                        };
                        db.PSNs.Add(psnObj);
                    }

                    foreach (var rReason in model.ReturnReasons)
                    {
                        var rrObj = new ReturnReason {
                            BeneficiaryID = beneficiary.BeneficiaryID,
                            ReasonCode    = rReason.ReasonCode,
                            Other         = rReason.Other
                        };
                        db.ReturnReasons.Add(rrObj);
                    }

                    foreach (var d in model.Determinations)
                    {
                        var dObj = new Determination {
                            BeneficiaryID     = beneficiary.BeneficiaryID,
                            DeterminationCode = d.DeterminationCode,
                            AnswerCode        = d.AnswerCode,
                            Other             = d.Other
                        };
                        db.Determinations.Add(dObj);
                    }

                    foreach (var m in model.MoneySources)
                    {
                        var moneySObj = new MoneySource {
                            BeneficiaryID    = beneficiary.BeneficiaryID,
                            MoneySourceCode  = m.MoneySourceCode,
                            MoneySourceOther = m.MoneySourceOther
                        };
                        db.MoneySources.Add(moneySObj);
                    }

                    foreach (var bi in model.BroughtItems)
                    {
                        var biObj = new BroughtItem {
                            BeneficiaryID = beneficiary.BeneficiaryID,
                            ItemCode      = bi.ItemCode,
                            ItemOther     = bi.ItemOther
                        };
                        db.BroughtItems.Add(biObj);
                    }

                    foreach (var p in model.PostArrivalNeeds)
                    {
                        var panObj = new PostArrivalNeed {
                            BeneficiaryID = beneficiary.BeneficiaryID,
                            NeedCode      = p.NeedCode,
                            Provided      = p.Provided,
                            ProvidedDate  = p.ProvidedDate,
                            Comment       = p.Comment
                        };
                        db.PostArrivalNeeds.Add(panObj);
                    }

                    if (model.HaveFamilyBenefited == true)
                    {
                        foreach (var a in model.BenefitedFromOrgs)
                        {
                            var assisOrgInfo = new BenefitedFromOrg
                            {
                                BeneficiaryID      = beneficiary.BeneficiaryID,
                                Date               = a.Date,
                                ProvinceCode       = a.ProvinceCode,
                                DistrictID         = a.DistrictID,
                                Village            = a.Village,
                                OrgCode            = a.OrgCode,
                                AssistanceProvided = a.AssistanceProvided
                            };
                            db.BenefitedFromOrgs.Add(assisOrgInfo);
                        }
                    }

                    foreach (var tran  in model.Transportations)
                    {
                        var tranObj = new Transportation {
                            BeneficiaryID = beneficiary.BeneficiaryID,
                            TypedCode     = tran.TypedCode,
                            Other         = tran.Other
                        };
                        db.Transportations.Add(tranObj);
                    }

                    foreach (var li in model.LivelihoodEmpNeeds)
                    {
                        var liObj = new LivelihoodEmpNeed {
                            BeneficiaryID = beneficiary.BeneficiaryID,
                            NeedCode      = li.NeedCode
                        };
                        db.LivelihoodEmpNeeds.Add(liObj);
                    }

                    foreach (var needTool in model.NeedTools)
                    {
                        var needToolObj = new NeedTool {
                            BeneficiaryID = beneficiary.BeneficiaryID,
                            ToolCode      = needTool.ToolCode,
                            Other         = needTool.Other
                        };
                        db.NeedTools.Add(needToolObj);
                    }

                    foreach (var mConcern in model.MainConcerns)
                    {
                        var mcObj = new MainConcern {
                            BeneficiaryID = beneficiary.BeneficiaryID,
                            ConcernCode   = mConcern.ConcernCode,
                            Other         = mConcern.Other
                        };
                        db.MainConcerns.Add(mcObj);
                    }

                    foreach (var hc in model.HostCountrySchools)
                    {
                        var hcObj = new HostCountrySchool {
                            BeneficiaryID  = beneficiary.BeneficiaryID,
                            SchoolTypeCode = hc.SchoolTypeCode
                        };
                        db.HostCountrySchools.Add(hcObj);
                    }

                    db.SaveChanges();

                    trans.Commit();
                    return(true);
                }
                catch (Exception e)
                {
                    trans.Rollback();
                    return(false);
                }
            }
        }
        public async Task <IActionResult> Put(int id, [FromBody] BeneficiaryFormDto model)
        {
            var beneficiaryInDb = db.Beneficiaries.Where(b => b.IsActive == true && b.BeneficiaryID == id).FirstOrDefault();

            if (beneficiaryInDb == null)
            {
                return(NotFound("Beneficiary not found."));
            }
            if (model != null)
            {
                using (var trans = db.Database.BeginTransaction())
                {
                    try
                    {
                        var currentUser = HttpContext.User;
                        _mapper.Map(model, beneficiaryInDb);
                        beneficiaryInDb.LastUpdatedBy   = currentUser.Identity.Name;
                        beneficiaryInDb.LastUpdatedDate = DateTime.Now;
                        //beneficiaryInDb.upd
                        db.SaveChanges();
                        var _Individuals = db.Individuals.Where(x => x.BeneficiaryID == id).ToList();
                        _Individuals.ForEach(x => x.IsActive = false);
                        db.SaveChanges();
                        foreach (var row in model.Individuals)
                        {
                            if (row != null)
                            {
                                if (row.IndividualID == 0)
                                {
                                    var newIndividual = _mapper.Map <Individual>(row);
                                    newIndividual.BeneficiaryID = model.BeneficiaryID;
                                    newIndividual.IsActive      = true;
                                    db.Individuals.Add(newIndividual);
                                    db.SaveChanges();
                                }
                                else
                                {
                                    var individualInDb = db.Individuals.Where(i => i.BeneficiaryID == model.BeneficiaryID &&
                                                                              i.IndividualID == row.IndividualID).FirstOrDefault();
                                    if (individualInDb != null)
                                    {
                                        _mapper.Map(row, individualInDb);
                                        individualInDb.BeneficiaryID = model.BeneficiaryID;
                                        individualInDb.IsActive      = true;
                                        db.SaveChanges();
                                    }
                                }
                            }
                        }

                        db.PSNs.Where(x => x.BeneficiaryID == model.BeneficiaryID).ToList().ForEach(x => db.PSNs.Remove(x));

                        foreach (var psn in model.PSNs)
                        {
                            var psnObj = new PSN
                            {
                                BeneficiaryID = beneficiaryInDb.BeneficiaryID,
                                PSNCode       = psn.LookupCode,
                                PSNOther      = psn.Other
                            };
                            db.PSNs.Add(psnObj);
                        }
                        db.ReturnReasons.Where(x => x.BeneficiaryID == model.BeneficiaryID).ToList().ForEach(x => db.ReturnReasons.Remove(x));

                        foreach (var rReason in model.ReturnReasons)
                        {
                            var rrObj = new ReturnReason
                            {
                                BeneficiaryID = beneficiaryInDb.BeneficiaryID,
                                ReasonCode    = rReason.LookupCode,
                                Other         = rReason.Other
                            };
                            db.ReturnReasons.Add(rrObj);
                        }

                        db.Determinations.Where(x => x.BeneficiaryID == model.BeneficiaryID).ToList().ForEach(x => db.Determinations.Remove(x));

                        foreach (var d in model.Determinations)
                        {
                            var dObj = new Determination
                            {
                                BeneficiaryID     = beneficiaryInDb.BeneficiaryID,
                                DeterminationCode = d.LookupCode,
                                AnswerCode        = d.AnswerCode,
                                Other             = d.Other
                            };
                            db.Determinations.Add(dObj);
                        }

                        db.MoneySources.Where(x => x.BeneficiaryID == model.BeneficiaryID).ToList().ForEach(x => db.MoneySources.Remove(x));

                        foreach (var m in model.MoneySources)
                        {
                            var moneySObj = new MoneySource
                            {
                                BeneficiaryID    = beneficiaryInDb.BeneficiaryID,
                                MoneySourceCode  = m.LookupCode,
                                MoneySourceOther = m.Other
                            };
                            db.MoneySources.Add(moneySObj);
                        }

                        db.BroughtItems.Where(x => x.BeneficiaryID == model.BeneficiaryID).ToList().ForEach(x => db.BroughtItems.Remove(x));

                        foreach (var bi in model.BroughtItems)
                        {
                            var biObj = new BroughtItem
                            {
                                BeneficiaryID = beneficiaryInDb.BeneficiaryID,
                                ItemCode      = bi.LookupCode,
                                ItemOther     = bi.Other
                            };
                            db.BroughtItems.Add(biObj);
                        }

                        db.PostArrivalNeeds.Where(x => x.BeneficiaryID == model.BeneficiaryID).ToList().ForEach(x => db.PostArrivalNeeds.Remove(x));

                        foreach (var p in model.PostArrivalNeeds)
                        {
                            var panObj = new PostArrivalNeed
                            {
                                BeneficiaryID = beneficiaryInDb.BeneficiaryID,
                                NeedCode      = p.LookupCode,
                                Provided      = p.IsProvided,
                                ProvidedDate  = (DateTime)p.ProvidedDate,
                                Comment       = p.Comment
                            };
                            db.PostArrivalNeeds.Add(panObj);
                        }
                        db.BenefitedFromOrgs.Where(x => x.BeneficiaryID == model.BeneficiaryID).ToList().ForEach(x => db.BenefitedFromOrgs.Remove(x));
                        if (model.HaveFamilyBenefited == true)
                        {
                            foreach (var a in model.BenefitedFromOrgs)
                            {
                                var assisOrgInfo = new BenefitedFromOrg
                                {
                                    BeneficiaryID      = beneficiaryInDb.BeneficiaryID,
                                    Date               = a.Date,
                                    ProvinceCode       = a.ProvinceCode,
                                    DistrictID         = a.DistrictID,
                                    Village            = a.Village,
                                    OrgCode            = a.OrgCode,
                                    AssistanceProvided = a.AssistanceProvided
                                };
                                db.BenefitedFromOrgs.Add(assisOrgInfo);
                            }
                        }
                        db.Transportations.Where(x => x.BeneficiaryID == model.BeneficiaryID).ToList().ForEach(x => db.Transportations.Remove(x));

                        foreach (var tran in model.Transportations)
                        {
                            var tranObj = new Transportation
                            {
                                BeneficiaryID = beneficiaryInDb.BeneficiaryID,
                                TypedCode     = tran.LookupCode,
                                Other         = tran.Other
                            };
                            db.Transportations.Add(tranObj);
                        }
                        db.LivelihoodEmpNeeds.Where(x => x.BeneficiaryID == model.BeneficiaryID).ToList().ForEach(x => db.LivelihoodEmpNeeds.Remove(x));

                        foreach (var li in model.LivelihoodEmpNeeds)
                        {
                            var liObj = new LivelihoodEmpNeed
                            {
                                BeneficiaryID = beneficiaryInDb.BeneficiaryID,
                                NeedCode      = li.LookupCode
                            };
                            db.LivelihoodEmpNeeds.Add(liObj);
                        }

                        db.NeedTools.Where(x => x.BeneficiaryID == model.BeneficiaryID).ToList().ForEach(x => db.NeedTools.Remove(x));

                        foreach (var needTool in model.NeedTools)
                        {
                            var needToolObj = new NeedTool
                            {
                                BeneficiaryID = beneficiaryInDb.BeneficiaryID,
                                ToolCode      = needTool.LookupCode,
                                Other         = needTool.Other
                            };
                            db.NeedTools.Add(needToolObj);
                        }

                        db.MainConcerns.Where(x => x.BeneficiaryID == model.BeneficiaryID).ToList().ForEach(x => db.MainConcerns.Remove(x));

                        foreach (var mConcern in model.MainConcerns)
                        {
                            var mcObj = new MainConcern
                            {
                                BeneficiaryID = beneficiaryInDb.BeneficiaryID,
                                ConcernCode   = mConcern.LookupCode,
                                Other         = mConcern.Other
                            };
                            db.MainConcerns.Add(mcObj);
                        }

                        db.HostCountrySchools.Where(x => x.BeneficiaryID == model.BeneficiaryID).ToList().ForEach(x => db.HostCountrySchools.Remove(x));

                        foreach (var hc in model.HostCountrySchools)
                        {
                            var hcObj = new HostCountrySchool
                            {
                                BeneficiaryID  = beneficiaryInDb.BeneficiaryID,
                                SchoolTypeCode = hc.LookupCode
                            };
                            db.HostCountrySchools.Add(hcObj);
                        }

                        db.SaveChanges();

                        trans.Commit();
                        return(NoContent());
                    }
                    catch (Exception e)
                    {
                        trans.Rollback();
                        throw new Exception($"Updating failed on save");
                    }
                }
            }

            return(NoContent());
        }
        public bool Post([FromBody] BeneficiaryDto model)
        {
            if (model != null)
            {
                using (var trans = db.Database.BeginTransaction())
                {
                    try
                    {
                        var currentUser = HttpContext.User;
                        var beneficiary = _mapper.Map <Beneficiary>(model);
                        beneficiary.IsSubmitted = true;
                        db.Beneficiaries.Add(beneficiary);
                        db.SaveChanges();

                        foreach (var ind in model.Individuals)
                        {
                            var member = _mapper.Map <Individual>(model.Individuals);
                            member.IsActive = true;
                            db.Individuals.Add(member);
                        }

                        foreach (var psn in model.PSNs)
                        {
                            var psnObj = new PSN
                            {
                                BeneficiaryID = beneficiary.BeneficiaryID,
                                PSNCode       = psn.PSNCode,
                                PSNOther      = psn.PSNOther
                            };
                            db.PSNs.Add(psnObj);
                        }

                        foreach (var rReason in model.ReturnReasons)
                        {
                            var rrObj = new ReturnReason
                            {
                                BeneficiaryID = beneficiary.BeneficiaryID,
                                ReasonCode    = rReason.ReasonCode,
                                Other         = rReason.Other
                            };
                            db.ReturnReasons.Add(rrObj);
                        }

                        foreach (var d in model.Determinations)
                        {
                            var dObj = new Determination
                            {
                                BeneficiaryID     = beneficiary.BeneficiaryID,
                                DeterminationCode = d.DeterminationCode,
                                AnswerCode        = d.AnswerCode,
                                Other             = d.Other
                            };
                            db.Determinations.Add(dObj);
                        }

                        foreach (var m in model.MoneySources)
                        {
                            var moneySObj = new MoneySource
                            {
                                BeneficiaryID    = beneficiary.BeneficiaryID,
                                MoneySourceCode  = m.MoneySourceCode,
                                MoneySourceOther = m.MoneySourceOther
                            };
                            db.MoneySources.Add(moneySObj);
                        }

                        foreach (var bi in model.BroughtItems)
                        {
                            var biObj = new BroughtItem
                            {
                                BeneficiaryID = beneficiary.BeneficiaryID,
                                ItemCode      = bi.ItemCode,
                                ItemOther     = bi.ItemOther
                            };
                            db.BroughtItems.Add(biObj);
                        }

                        foreach (var p in model.PostArrivalNeeds)
                        {
                            var panObj = new PostArrivalNeed
                            {
                                BeneficiaryID = beneficiary.BeneficiaryID,
                                NeedCode      = p.NeedCode,
                                Provided      = p.Provided,
                                ProvidedDate  = p.ProvidedDate,
                                Comment       = p.Comment
                            };
                            db.PostArrivalNeeds.Add(panObj);
                        }

                        if (model.HaveFamilyBenefited == true)
                        {
                            foreach (var a in model.BenefitedFromOrgs)
                            {
                                var assisOrgInfo = new BenefitedFromOrg
                                {
                                    BeneficiaryID      = beneficiary.BeneficiaryID,
                                    Date               = a.Date,
                                    ProvinceCode       = a.ProvinceCode,
                                    DistrictID         = a.DistrictID,
                                    Village            = a.Village,
                                    OrgCode            = a.OrgCode,
                                    AssistanceProvided = a.AssistanceProvided
                                };
                                db.BenefitedFromOrgs.Add(assisOrgInfo);
                            }
                        }

                        foreach (var tran in model.Transportations)
                        {
                            var tranObj = new Transportation
                            {
                                BeneficiaryID = beneficiary.BeneficiaryID,
                                TypedCode     = tran.TypedCode,
                                Other         = tran.Other
                            };
                            db.Transportations.Add(tranObj);
                        }

                        foreach (var li in model.LivelihoodEmpNeeds)
                        {
                            var liObj = new LivelihoodEmpNeed
                            {
                                BeneficiaryID = beneficiary.BeneficiaryID,
                                NeedCode      = li.NeedCode
                            };
                            db.LivelihoodEmpNeeds.Add(liObj);
                        }

                        foreach (var needTool in model.NeedTools)
                        {
                            var needToolObj = new NeedTool
                            {
                                BeneficiaryID = beneficiary.BeneficiaryID,
                                ToolCode      = needTool.ToolCode,
                                Other         = needTool.Other
                            };
                            db.NeedTools.Add(needToolObj);
                        }

                        foreach (var mConcern in model.MainConcerns)
                        {
                            var mcObj = new MainConcern
                            {
                                BeneficiaryID = beneficiary.BeneficiaryID,
                                ConcernCode   = mConcern.ConcernCode,
                                Other         = mConcern.Other
                            };
                            db.MainConcerns.Add(mcObj);
                        }

                        foreach (var hc in model.HostCountrySchools)
                        {
                            var hcObj = new HostCountrySchool
                            {
                                BeneficiaryID  = beneficiary.BeneficiaryID,
                                SchoolTypeCode = hc.SchoolTypeCode
                            };
                            db.HostCountrySchools.Add(hcObj);
                        }

                        db.SaveChanges();

                        trans.Commit();
                        return(true);
                    }
                    catch (Exception e)
                    {
                        trans.Rollback();
                        return(false);
                    }
                }
            }
            return(false);
        }
示例#10
0
        protected override void Seed(ZcrlTenderContext context)
        {
            UserSession.CreateUser("Адміністратор", "1234567", "Обліковий запис адміністратора системи");

            KekvCode k1 = new KekvCode {
                Code = "2110", Name = "Оплата праці"
            };
            KekvCode k2 = new KekvCode {
                Code = "2210", Name = "Предмети, матеріали, обладнання та інвентар"
            };
            KekvCode k3 = new KekvCode {
                Code = "2220", Name = "Медикаменти та перев'язувальні матеріали"
            };
            KekvCode k4 = new KekvCode {
                Code = "2230", Name = "Продукти харчування"
            };
            KekvCode k5 = new KekvCode {
                Code = "2240", Name = "Оплата послуг (крім комунальних)"
            };
            KekvCode k6 = new KekvCode {
                Code = "2271", Name = "Оплата теплопостачання"
            };
            KekvCode k7 = new KekvCode {
                Code = "2272", Name = "Оплата водопостачання та водовідведення"
            };
            KekvCode k8 = new KekvCode {
                Code = "2273", Name = "Оплата електроенергії"
            };
            KekvCode k9 = new KekvCode {
                Code = "2274", Name = "Оплата природного газу"
            };
            KekvCode k10 = new KekvCode {
                Code = "2275", Name = "Оплата інших енергоносіїв"
            };
            KekvCode k11 = new KekvCode {
                Code = "2281", Name = "Дослідження і розробки, окремі заходи розвитку по реалізації державних (регіональних) програм"
            };
            KekvCode k12 = new KekvCode {
                Code = "2282", Name = "Окремі заходи по реалізації державних (регіональних) програм, не віднесені до заходів розвитку"
            };
            KekvCode k13 = new KekvCode {
                Code = "2710", Name = "Виплата пенсій і допомоги"
            };
            KekvCode k14 = new KekvCode {
                Code = "2730", Name = "Інші виплати населенню"
            };
            KekvCode k15 = new KekvCode {
                Code = "2800", Name = "Інші поточні видатки"
            };
            KekvCode k16 = new KekvCode {
                Code = "3110", Name = "Придбання обладнання і предметів довгострокового користування"
            };

            context.KekvCodes.Add(k1);
            context.KekvCodes.Add(k2);
            context.KekvCodes.Add(k3);
            context.KekvCodes.Add(k4);
            context.KekvCodes.Add(k5);
            context.KekvCodes.Add(k6);
            context.KekvCodes.Add(k7);
            context.KekvCodes.Add(k8);
            context.KekvCodes.Add(k9);
            context.KekvCodes.Add(k10);
            context.KekvCodes.Add(k11);
            context.KekvCodes.Add(k12);
            context.KekvCodes.Add(k13);
            context.KekvCodes.Add(k14);
            context.KekvCodes.Add(k15);
            context.KekvCodes.Add(k16);
            context.SaveChanges();

            int         priority = 1;
            MoneySource ms1      = new MoneySource {
                Name = "Місцевий бюджет", ViewPriority = priority++
            };
            MoneySource ms2 = new MoneySource {
                Name = "Додаткова дотація", ViewPriority = priority++
            };
            MoneySource ms3 = new MoneySource {
                Name = "Медична субвенція", ViewPriority = priority++
            };
            MoneySource ms4 = new MoneySource {
                Name = "Долинська субвенція", ViewPriority = priority++
            };
            MoneySource ms5 = new MoneySource {
                Name = "Біленьківська субвенція", ViewPriority = priority++
            };
            MoneySource ms6 = new MoneySource {
                Name = "Широківська субвенція", ViewPriority = priority++
            };
            MoneySource ms7 = new MoneySource {
                Name = "Суми за дорученням", ViewPriority = priority++
            };
            MoneySource ms8 = new MoneySource {
                Name = "Спецрахунок", ViewPriority = priority++
            };

            context.MoneySources.Add(ms1);
            context.MoneySources.Add(ms2);
            context.MoneySources.Add(ms3);
            context.MoneySources.Add(ms4);
            context.MoneySources.Add(ms5);
            context.MoneySources.Add(ms6);
            context.MoneySources.Add(ms7);
            context.MoneySources.Add(ms8);
            context.SaveChanges();

            base.Seed(context);
        }
示例#11
0
 public void Update(MoneySource moneySource, SqlConnection con = null, SqlTransaction trans = null)
 {
     _adapter.Update(moneySource, con, trans);
 }