コード例 #1
0
        public JsonResult BackFillStatements(DateTime month)
        {
            if (!AuthorizationProvider.IsDataImporter())
            {
                return(Forbidden());
            }

            try
            {
                var statementProvider = new OwnerStatementProvider(_dbContext);
                var propertyProvider  = new PropertyProvider(_dbContext);
                var properties        = propertyProvider.All();
                foreach (CPL property in properties)
                {
                    if (property.PropertyStatus != "Dead")
                    {
                        try
                        {
                            // create/update owner statement record
                            var model = statementProvider.GetOwnerStatement(month, property.PropertyCode);
                            model.PropertyName = model.PropertyName.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries)[0].Trim();
                            var entity = statementProvider.Retrieve(model);
                            if (entity != null)
                            {
                                statementProvider.MapData(model, ref entity);
                                statementProvider.Update(entity.OwnerStatementId, entity);
                            }
                            else
                            {
                                entity = new OwnerStatement();
                                statementProvider.MapData(model, ref entity);
                                statementProvider.Create(entity);
                            }
                            statementProvider.Commit();
                        }
                        catch (Exception ex)
                        {
                            return(Json(ex.Message, JsonRequestBehavior.AllowGet));
                        }
                    }
                }
                return(Json("success-Statement", JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(ex.Message, JsonRequestBehavior.AllowGet));
            }
        }