示例#1
0
        public IHttpActionResult LogPharmacyVisit(Gln gln)
        {
            if (Equals(gln, null))
            {
                return(BadRequest());
            }

            var glnToUpdate     = _unitOfWork.Glns.FindSingle(g => g.Id == gln.Id);
            var glnBeforeUpdate = DtoHelper.CreateGlnIncludeChildrenDto(glnToUpdate);

            if (Equals(glnToUpdate, null))
            {
                return(BadRequest());
            }

            try
            {
                _logger.SiteVisitedLog(HttpContext.Current.User, glnBeforeUpdate);

                return(Ok());
            }
            catch (Exception ex)
            {
                _logger.FailedUpdateServerLog(HttpContext.Current.User, ex.Message, ex.InnerException, DtoHelper.CreateGlnIncludeChildrenDto(glnToUpdate), DtoHelper.CreateGlnIncludeChildrenDto(glnToUpdate));
                return(InternalServerError());
            }
        }
        public IHttpActionResult DeactivateAdditionalContact(int deactivateId, int replacementId)
        {
            if (deactivateId <= 0 || replacementId <= 0)
            {
                return(BadRequest());
            }

            var additionalContactToDeactivate = _unitOfWork.AdditionalContacts.FindSingle(ac => ac.Id == deactivateId);
            var replacementAdditionalContact  = _unitOfWork.AdditionalContacts.FindSingle(ac => ac.Id == replacementId);

            if (additionalContactToDeactivate == null)
            {
                return(BadRequest());
            }

            try
            {
                additionalContactToDeactivate.Active = false;

                _unitOfWork.Complete();

                _logger.SuccessfulUpdateServerLog(HttpContext.Current.User, DtoHelper.CreateAdditionalContactDto(replacementAdditionalContact),
                                                  DtoHelper.CreateAdditionalContactDto(replacementAdditionalContact));

                return(Ok());
            }
            catch (Exception ex)
            {
                _logger.FailedUpdateServerLog(HttpContext.Current.User, ex.Message, ex.InnerException, $"Attempt to deactivate Additional Contact Id: {deactivateId}", $"Supplied replacement Additional Contact Id: {replacementId}");

                return(InternalServerError(ex));
            }
        }
示例#3
0
        public IHttpActionResult AddAddress(Address newAddress)
        {
            if (Equals(newAddress, null))
            {
                return(BadRequest());
            }

            try
            {
                newAddress.Version = 1;
                newAddress.Country = "GBR";
                newAddress.Active  = true;
                _unitOfWork.Addresses.Add(newAddress);
                _unitOfWork.Complete();

                _logger.SuccessfullyAddedServerLog(HttpContext.Current.User, DtoHelper.CreateAddressDto(newAddress));

                return(Ok(newAddress));
            }
            catch (Exception ex)
            {
                _logger.FailedToCreateServerLog <Exception, object>(HttpContext.Current.User, ex.Message, ex.InnerException);

                return(InternalServerError());
            }
        }
        public IHttpActionResult AddNewAdditionalContact([FromBody] AdditionalContact newAdditionalContact)
        {
            if (Equals(newAdditionalContact, null))
            {
                return(BadRequest());
            }

            var additionalContact = _unitOfWork.AdditionalContacts.Find(ac => ac.Email == newAdditionalContact.Email);

            if (additionalContact.Any())
            {
                return(Content(HttpStatusCode.Conflict, "Contact with same email already exists."));
            }

            try
            {
                _unitOfWork.AdditionalContacts.Add(newAdditionalContact);
                _unitOfWork.Complete();

                _logger.SuccessfullyAddedServerLog(HttpContext.Current.User, DtoHelper.CreateAdditionalContactDto(newAdditionalContact));

                return(Ok(DtoHelper.CreateAdditionalContactDto(newAdditionalContact)));
            }
            catch (Exception ex)
            {
                _logger.FailedToCreateServerLog(HttpContext.Current.User, ex.Message, ex.InnerException, DtoHelper.CreateAdditionalContactDto(newAdditionalContact));

                return(InternalServerError(ex));
            }
        }
        public IHttpActionResult IprUpdate(Ipr ipr)
        {
            if (Equals(null, ipr))
            {
                return(BadRequest());
            }

            var findIpr = _unitOfWork.Ipr.FindSingle(i => i.Id == ipr.Id);

            if (Equals(null, findIpr))
            {
                return(NotFound());
            }

            _unitOfWork.Ipr.UpdateIpr(ipr);

            try
            {
                _unitOfWork.Complete();
                var updatedIpr = _unitOfWork.Ipr.FindSingle(i => i.Id == ipr.Id);
                return(Ok(DtoHelper.CreateIprDto(updatedIpr)));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        // PUT: api/Products/5
        public IHttpActionResult Put(int id, [FromBody] DtoProducts product)
        {
            var updatetProduct = DtoHelper.FromDtoProduct_To_Product(product);

            if (!ModelState.IsValid)
            {
                return(BadRequest("det er her det feiler: " + ModelState));
            }

            if (id != product._id)
            {
                return(BadRequest("Sorry, seems something wrong. Couldn't deter mine record to update."));
            }

            db.Entry(updatetProduct).State = EntityState.Modified;
            db.SaveChanges();
            product.product = product._id;


            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            return(Ok(product));
        }
        public HttpStatusCode DeactivateAdditionalContact(int deactivateId, int?replacementId)
        {
            var additionalContactToDeactivate = _db.AdditionalContacts.SingleOrDefault(pc => pc.Id == deactivateId);
            var replacementAdditionalContact  = _db.AdditionalContacts.SingleOrDefault(pc => pc.Id == replacementId);

            if (Equals(additionalContactToDeactivate, null))
            {
                return(HttpStatusCode.BadRequest);
            }

            try
            {
                additionalContactToDeactivate.Active = false;

                _db.SaveChanges();

                _mongoMongoLogger.SuccessfulUpdateServerLog(HttpContext.Current.User, DtoHelper.CreateAdditionalContactDto(replacementAdditionalContact),
                                                            DtoHelper.CreateAdditionalContactDto(replacementAdditionalContact));

                return(HttpStatusCode.OK);
            }
            catch (Exception ex)
            {
                _mongoMongoLogger.FailedUpdateServerLog(HttpContext.Current.User, ex.Message, ex.InnerException, $"Attempt to deactivate Additional Contact Id: {deactivateId}", $"Supplied replacement Additional Contact Id: {replacementId}");

                return(HttpStatusCode.InternalServerError);
            }
        }
示例#8
0
        public GlnDto GetGlnByGln(string gln)
        {
            var findGlns = _db.Glns.SingleOrDefault(b => b.OwnGln == gln);

            if (!Equals(findGlns, null))
            {
                //Everytime gln is fetched calculate its children to ensure it is up to date
                var currentDbVersion = _db.Glns.SingleOrDefault(bc => bc.OwnGln == gln).Version;
                if (ConcurrencyChecker.canSaveChanges(findGlns.Version, currentDbVersion))
                {
                    findGlns.NumberOfChildren = CalculateChildrenNumbers(findGlns.OwnGln);
                }

                // If primary then GLN will not have a parent
                if (!findGlns.Primary)
                {
                    findGlns.ParentDescriptionPurpose =
                        _db.Glns.SingleOrDefault(bc => bc.OwnGln == findGlns.ParentGln).FriendlyDescriptionPurpose;
                }

                _db.SaveChanges();
            }

            return(DtoHelper.CreateGlnIncludeChildrenDto(findGlns));
        }
示例#9
0
        public HttpStatusCode UpdatePrimaryContact(PrimaryContact contact)
        {
            try
            {
                var contactToUpdate     = _db.PrimaryContacts.SingleOrDefault(c => c.Id == contact.Id);
                var contactBeforeUpdate = DtoHelper.CreatePrimaryContactDto(contactToUpdate);

                if (contactToUpdate != null)
                {
                    contactToUpdate.Name       = contact.Name;
                    contactToUpdate.Email      = contact.Email;
                    contactToUpdate.Telephone  = contact.Telephone;
                    contactToUpdate.Function   = contact.Function;
                    contactToUpdate.Salutation = contact.Salutation;
                    contactToUpdate.Fax        = contact.Fax;
                    contactToUpdate.Active     = contact.Active;
                }

                _db.SaveChanges();

                _mongoMongoLogger.SuccessfulUpdateServerLog(HttpContext.Current.User, contactBeforeUpdate, DtoHelper.CreatePrimaryContactDto(contactToUpdate));

                return(HttpStatusCode.OK);
            }
            catch (Exception ex)
            {
                _mongoMongoLogger.FailedUpdateServerLog <Exception, object, object>(HttpContext.Current.User, ex.Message,
                                                                                    ex.InnerException, contact);

                return(HttpStatusCode.InternalServerError);
            }
        }
示例#10
0
        public GlnDto GetGlnById(int id)
        {
            var gln = _db.Glns.SingleOrDefault(b => b.Id == id);

            if (!Equals(gln, null))
            {
                //Everytime gln is fetched calculate its children to ensure it is up to date
                var currentDbVersion = _db.Glns.SingleOrDefault(bc => bc.Id == id).Version;
                if (ConcurrencyChecker.canSaveChanges(gln.Version, currentDbVersion))
                {
                    gln.NumberOfChildren = CalculateChildrenNumbers(gln.OwnGln);
                }

                // If primary then GLN will not have a parent
                try
                {
                    if (!gln.Primary)
                    {
                        gln.ParentDescriptionPurpose =
                            _db.Glns.SingleOrDefault(bc => bc.OwnGln == gln.ParentGln).FriendlyDescriptionPurpose;
                    }

                    _db.SaveChanges();
                }
                catch (Exception ex)
                {
                    var failedMsg = $"Failed to update Parent Description Purpose on {gln.OwnGln} " +
                                    $". Exception generated: {ex}";

                    _mongoMongoLogger.FailedUpdateServerLog <Exception, string, object>(HttpContext.Current.User, ex.Message, ex.InnerException, failedMsg);
                }
            }

            return(DtoHelper.CreateGlnIncludeChildrenDto(gln));
        }
        public IHttpActionResult AddNewPrimaryContact([FromBody] PrimaryContact newContact)
        {
            if (Equals(newContact, null))
            {
                return(BadRequest());
            }

            var contactAlreadyExists = _unitOfWork.PrimaryContacts.Find(pc => pc.Email == newContact.Email);

            if (!contactAlreadyExists.Any())
            {
                try
                {
                    _unitOfWork.PrimaryContacts.Add(newContact);
                    _unitOfWork.Complete();

                    var createdContact = _unitOfWork.PrimaryContacts.FindSingle(pc => pc.Email == newContact.Email);

                    return(Ok(DtoHelper.CreatePrimaryContactDto(createdContact)));
                }
                catch (Exception ex)
                {
                    _logger.FailedUpdateServerLog <Exception, object, object>(HttpContext.Current.User, ex.Message,
                                                                              ex.InnerException, DtoHelper.CreatePrimaryContactDto(newContact));

                    return(InternalServerError(ex));
                }
            }
            else
            {
                return(Conflict());
            }
        }
示例#12
0
        public IActionResult Edit(int id, int?itemId)
        {
            if (id < 0)
            {
                return(NotFound());
            }
            if (itemId.HasValue && itemId < 0)
            {
                return(NotFound());
            }
            var dictionary = _db.Dictionaries
                             .Include(d => d.Items)
                             .FirstOrDefault(t => t.Id == id);

            if (dictionary == null)
            {
                return(NotFound());
            }
            var model             = DtoHelper.GeEditDictionaryDto(dictionary);
            var isEditItemRequest = itemId.HasValue;

            if (isEditItemRequest)
            {
                model.AddedOrEditedItem = model.Items.FirstOrDefault(at => at.Id == itemId);
                if (model.AddedOrEditedItem == null)
                {
                    return(NotFound());
                }
            }
            return(View(model));
        }
示例#13
0
        // Finner koblingene mellom firma og kundet ype
        //Get /api/test

        public IEnumerable <CustomerToTypeDto> GetTest()
        {
            var cToTypeList = _context.CustomerToTypes.ToList();
            var dtoList     = DtoHelper.MapList(cToTypeList);

            return(null);
        }
示例#14
0
        public void GetDto()
        {
            //moke
            ContainerBuilder builder = new ContainerBuilder();

            builder.LoadAutoMapper();
            builder.RegisterType <AutoMapperProfile>();
            IContainer Container = builder.Build();

            using (var scope = Container.BeginLifetimeScope())
            {
                scope.Resolve <AutoMapperProfile>().Mapping(scope);
                PeopleDto result = new PeopleDto()
                {
                    Eye = "双眼皮", Mouth = "红润", Age = 18, IsMarried = false
                };
                PhysicalAttribute physical = new PhysicalAttribute()
                {
                    Eye = "双眼皮", Mouth = "红润"
                };
                SocialAttribute social = new SocialAttribute()
                {
                    Name = "张三", IsMarried = false, Age = 18
                };
                PeopleDto output = new DtoHelper(scope.Resolve <IMapper>()).GetDto(physical, social);
                //Assert.Same(result, output);
                Assert.Equal(JsonConvert.SerializeObject(result), JsonConvert.SerializeObject(output));
                outputHelper.WriteLine(JsonConvert.SerializeObject(output));
            }
        }
        public void UpdateAddress(Address address)
        {
            //var addressToUpdate = _db.Addresses.FirstOrDefault(a => a.Id == address.Id);

            var addressToUpdate     = _db.Addresses.Find(address.Id);
            var addressBeforeUpdate = DtoHelper.CreateAddressDto(addressToUpdate);

            try
            {
                addressToUpdate.Active           = address.Active;
                addressToUpdate.AddressLineOne   = address.AddressLineOne;
                addressToUpdate.AddressLineTwo   = address.AddressLineTwo;
                addressToUpdate.AddressLineThree = address.AddressLineThree;
                addressToUpdate.AddressLineFour  = address.AddressLineFour;
                addressToUpdate.City             = address.City;
                addressToUpdate.Country          = address.Country;
                addressToUpdate.RegionCounty     = address.RegionCounty;
                addressToUpdate.Postcode         = address.Postcode;
                addressToUpdate.Version          = addressToUpdate.Version + 1;
                addressToUpdate.Level            = address.Level;
                addressToUpdate.DeliveryNote     = address.DeliveryNote;

                _db.SaveChanges();
                //_unitOfWork.Complete();

                _mongoMongoLogger.SuccessfulUpdateServerLog(HttpContext.Current.User, addressBeforeUpdate, addressToUpdate);
            }
            catch (Exception ex)
            {
                _mongoMongoLogger.FailedUpdateServerLog <Exception, object, object>(HttpContext.Current.User, ex.Message, ex.InnerException, address);
            }
        }
示例#16
0
        public IHttpActionResult UpdateGln(Gln gln)
        {
            if (Equals(gln, null))
            {
                return(BadRequest());
            }

            var glnToUpdate     = _unitOfWork.Glns.FindSingle(g => g.Id == gln.Id);
            var glnBeforeUpdate = DtoHelper.CreateGlnIncludeChildrenDto(glnToUpdate);

            if (Equals(glnToUpdate, null))
            {
                return(BadRequest());
            }

            var currentDbVersion = glnToUpdate.Version;

            if (!ConcurrencyChecker.canSaveChanges(gln.Version, currentDbVersion))
            {
                _logger.ConcurrenyServerLog(HttpContext.Current.User, gln.Version, currentDbVersion);
                return(Conflict());
            }

            var updatedGln = _unitOfWork.Glns.UpdateGln(gln);

            try
            {
                _unitOfWork.Complete();

                var completed = _unitOfWork.Glns.FindSingle(g => g.Id == gln.Id);

                _logger.SuccessfulUpdateServerLog(HttpContext.Current.User, glnBeforeUpdate, DtoHelper.CreateGlnDto(completed));

                if (glnBeforeUpdate.ParentGln != glnToUpdate.ParentGln)
                {
                    if (!string.IsNullOrEmpty(glnBeforeUpdate.ParentGln))
                    {
                        // Update number of children on previous parent
                        var oldParent = _unitOfWork.Glns.FindSingle(g => g.OwnGln == glnBeforeUpdate.ParentGln);
                        oldParent.NumberOfChildren = _unitOfWork.Glns.Find(g => g.ParentGln == oldParent.OwnGln).Count();
                        _unitOfWork.Complete();
                    }

                    if (!string.IsNullOrEmpty(glnToUpdate.ParentGln))
                    {
                        // Update number of children on new parent that has aquired an additional child
                        var newParent = _unitOfWork.Glns.FindSingle(g => g.OwnGln == glnToUpdate.ParentGln);
                        newParent.NumberOfChildren = _unitOfWork.Glns.Find(g => g.ParentGln == newParent.OwnGln).Count();
                        _unitOfWork.Complete();
                    }
                }

                return(Ok(DtoHelper.CreateGlnIncludeChildrenDto(completed)));
            }
            catch (Exception ex)
            {
                _logger.FailedUpdateServerLog(HttpContext.Current.User, ex.Message, ex.InnerException, DtoHelper.CreateGlnDto(glnToUpdate), DtoHelper.CreateGlnIncludeChildrenDto(updatedGln));
                return(InternalServerError());
            }
        }
示例#17
0
        //Get /api/customer/1
        public CustomerDto GetCustomer(int Id)
        {
            var customer    = _context.Customers.SingleOrDefault(c => c.Id == Id);
            var dtoCustomer = DtoHelper.MapCustomerToDtoCustomer(customer);


            return(dtoCustomer);
        }
示例#18
0
        public GlnDto GetNextUnassignedGln()
        {
            var gln = _db.Glns.FirstOrDefault(b => !b.Assigned && !b.AlternativeSystemIsTruth);

            if (Equals(gln, null))
            {
                return(new GlnDto());
            }

            return(DtoHelper.CreateGlnIncludeChildrenDto(gln));
        }
示例#19
0
        private IEnumerable <GlnSummaryDto> ConvertAssociationsToDtoSummary(IEnumerable <Gln> associations)
        {
            var associationsDtos = new List <GlnSummaryDto>();

            foreach (var a in associations)
            {
                associationsDtos.Add(DtoHelper.CreateGlnSummaryDto(a));
            }

            return(associationsDtos);
        }
        public IHttpActionResult GetGlnTagType(int id)
        {
            var glnTagType = _unitOfWork.GlnTagType.FindSingle(tt => tt.GlnTagTypeId == id);

            if (glnTagType == null)
            {
                return(NotFound());
            }

            return(Ok(DtoHelper.CreateGlnTagTypeDto(glnTagType)));
        }
        public IHttpActionResult GetPrimaryContactById(int id)
        {
            var contact = _unitOfWork.PrimaryContacts.FindSingle(pc => pc.Id == id);

            if (Equals(contact, null))
            {
                return(BadRequest());
            }

            return(Ok(DtoHelper.CreatePrimaryContactDto(contact)));
        }
示例#22
0
        // Finner en eller flere kundetyper for et firma
        //Get /api/Test/1

        public IEnumerable <CustomerDto> GetTest(int Id)
        {
            List <Customer> types    = new List <Customer>();
            var             customer = _context.CustomerToTypes.Where(c => c.CustomerTypeId == Id).ToList();

            foreach (var type in customer)
            {
                types.Add(type.Customer);
            }
            return(DtoHelper.MapCustomerListToDto(types));
        }
示例#23
0
        public IHttpActionResult GetPrimary()
        {
            var primary = _unitOfWork.Glns.FindSingle(gln => gln.Primary);

            if (Equals(primary, null))
            {
                return(NotFound());
            }

            return(Ok(DtoHelper.CreateGlnIncludeChildrenDto(primary)));
        }
示例#24
0
        public IHttpActionResult GetAddress(int id)
        {
            var address = _unitOfWork.Addresses.FindSingle(a => a.Id == id);

            if (Equals(address, null))
            {
                return(NotFound());
            }

            return(Ok(DtoHelper.CreateAddressDto(address)));
        }
示例#25
0
        // Finner en eller flere kundetyper for et firma
        //Get /api/CustomerToTypes/1

        public IEnumerable <CustomerTypeDto> GetCustomerToTypes(int Id)
        {
            List <CustomerType> types = new List <CustomerType>();
            var customerToType        = _context.CustomerToTypes.Where(c => c.CustomerId == Id).ToList();

            foreach (var type in customerToType)
            {
                types.Add(type.CustomerType);
            }
            return(DtoHelper.MapTypeListToDtoList(types));
        }
示例#26
0
        public IHttpActionResult GetGlnTag(int id)
        {
            GlnTag glnTag = _unitOfWork.GlnTag.FindSingle(tt => tt.GlnTagId == id);

            if (glnTag == null)
            {
                return(NotFound());
            }

            return(Ok(DtoHelper.CreateGlnTagDto(glnTag)));
        }
示例#27
0
        public IHttpActionResult CreateCustomer(CustomerDto dtoCustomer)
        {
            var customer = DtoHelper.MapDtoCustomerToCustomer(dtoCustomer);

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            _context.Customers.Add(customer);
            _context.SaveChanges();
            return(Created(new Uri(Request.RequestUri + "/" + customer.Id), dtoCustomer));
        }
        public IHttpActionResult UpdateAdditionalContact(AdditionalContact additionalContact)
        {
            if (Equals(additionalContact, null))
            {
                return(BadRequest());
            }

            var additionalContactToUpdate =
                _unitOfWork.AdditionalContacts.FindSingle(ac => ac.Id == additionalContact.Id);

            if (additionalContactToUpdate == null)
            {
                return(BadRequest());
            }

            var additionalContactBeforeUpdate = DtoHelper.CreateAdditionalContactDto(additionalContact);

            try
            {
                if (ConcurrencyChecker.canSaveChanges(additionalContact.Version, additionalContactToUpdate.Version))
                {
                    additionalContactToUpdate.Name                   = additionalContact.Name;
                    additionalContactToUpdate.Email                  = additionalContact.Email;
                    additionalContactToUpdate.Telephone              = additionalContact.Telephone;
                    additionalContactToUpdate.System                 = additionalContact.System;
                    additionalContactToUpdate.Fax                    = additionalContact.Fax;
                    additionalContactToUpdate.Salutation             = additionalContact.Salutation;
                    additionalContactToUpdate.Version                = additionalContact.Version + 1;
                    additionalContactToUpdate.Role                   = additionalContact.Role;
                    additionalContactToUpdate.NotificationSubscriber = additionalContact.NotificationSubscriber;
                    additionalContactToUpdate.Active                 = additionalContact.Active;

                    _unitOfWork.Complete();

                    _logger.SuccessfulUpdateServerLog(HttpContext.Current.User, DtoHelper.CreateAdditionalContactDto(additionalContact), DtoHelper.CreateAdditionalContactDto(additionalContactToUpdate));

                    return(Ok(DtoHelper.CreateAdditionalContactDto(additionalContactToUpdate)));
                }
                else
                {
                    _logger.ConcurrenyServerLog <object, object>(HttpContext.Current.User, additionalContact);

                    return(Conflict());
                }
            }
            catch (Exception ex)
            {
                _logger.FailedUpdateServerLog <Exception, object, object>(HttpContext.Current.User, ex.Message, ex.InnerException, DtoHelper.CreateAdditionalContactDto(additionalContact));

                return(InternalServerError());
            }
        }
示例#29
0
 public IActionResult Index(EditDictionaryDto model)
 {
     if (ModelState.IsValid)
     {
         var dictionary = new Dictionary {
             Name = model.Name
         };
         _db.Dictionaries.Add(dictionary);
         _db.SaveChanges();
         return(View(nameof(Edit), DtoHelper.GeEditDictionaryDto(dictionary)));
     }
     return(View(model));
 }
示例#30
0
        private async Task <List <BaseEntityDto <Volunteer> > > LoadVolunteerDtosAsync(List <Volunteer> volunteers)
        {
            var volunteersDto = new List <BaseEntityDto <Volunteer> >();

            foreach (var volunteer in volunteers)
            {
                var volunteerDto = await DtoHelper.LoadDto(volunteer, _httpClientService, "volunteer");

                volunteerDto.ConnectedUser = _connectedUserAuth;
                volunteersDto.Add(volunteerDto);
            }
            return(volunteersDto);
        }